这个sql放在数据库里执行没有问题。为哈程序一执行就报错了。
sql:
sql = Sqls.queryRecord("select * from activity apt where is_remove=0 and type=1 and CURDATE()<apt.endDate ORDER BY id desc");
异常:
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 'CURDATE()<endDate' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
@wendal 嗯,apt.是我发帖的时候加上去的,标明下是表的属性哈哈,不知道这是什么情况
if (curPage == 0) {
curPage = 1;
}
try {
Pager pager = dao.createPager(curPage, 10);//当前页,每页显示的个数,
sqlCount = Sqls.fetchInt("select count(*) from activity where is_remove=0 and type=1and CURDATE()<apt.endDate");//设置sql查询条件
pager.setRecordCount(dao.execute(sqlCount).getInt());//得到查询出来的总记录数,放入page对象
sql = Sqls.queryRecord("select * from activity apt where is_remove=0 and type=1 and CURDATE()<apt.endDate ORDER BY id desc");
sql.setPager(pager);
dao.execute(sql);
List<Record> list = sql.getList(Record.class);
map.put("recordList",list);
map.put("pager",pager);
map.put("result",1);
} catch (Exception e) {
e.printStackTrace();
map.put("result",2);
}
下面是异常信息:
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 'CURDATE()<apt.endDate' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
at com.mysql.jdbc.Util.getInstance(Util.java:382)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3593)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2620)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2570)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1474)
at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:200)
at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:43)
... 43 more
@wendal 我找到原因了 and type=1and CURDATE()<apt.endDate。。1和and中没有空格
@wendal 哈哈