public List getquery() throws Exception
{
Session session = super.getSession();
List list = null;
Query query = session.createQuery(" from User ");
query.setFirstResult(1*3);
query.setMaxResults(3);
list = query.list();
session.close();
return list;
}运行后报错
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.yangtianb.dao.UserInfoDAO.getquery(UserInfoDAO.java:46)
at com.yangtianb.web.Test.main(Test.java:11)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '() as rownumber_, user0_.id as id0_, user0_.name as name0_ from user user0_ ) as' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
我看你代码里面也没有什么问题
你检查下 User 的hibernite的配置文件是否有问题
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '() as rownumber_, user0_.id as id0_, user0_.name as name0_ from user user0_ ) as' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
这句话什么意思啊?
Query query = session.createQuery("from User");
org.hibernate.dialect.MySQLDialect
</property>
应该用MYSQL的,我用成了DB2的了。
但为什么方言用错了,对有些操作不会造成影响呢?比如我查询一个表的总条数,就能查出来··
有些语句是通用 但是MYSQL的分页语句跟DB2肯定不一样啊 MYSQL是用limit分页 DB2也许有其他的函数吧
恩恩 方言问题~