关于Jfinal使用Db.use(configName).save(tableName, record)模式保存数据报错的问题

本人最近在使用jfinal框架做多数据源sass系统,使用Db.use(configName).find(sql)做查询没有问题,但是使用Db.use(configName).save(tableName, record)或者Db.use(configName).update(tableName, record)都会报这个错,请大神们指点迷津。错误如下:

2017-09-13 17:18:28,461 ERROR [com.jfinal.core.ActionHandler] - /sassback/addOrUpdateCourseCate?identify=ep1&token=9ace11d1e4a04b70ac15aba420872dc9k3Ee2z&id=1&parentId=0&dirName=%E4%BA%A7%E5%93%81%E8%90%A5%E9%94%801&imgUrl=/sassFiles/images/2017/09/12/course_cate_cover.png&sortNo=1&remark=%E5%A4%87%E6%B3%A8%E4%B8%8B%E5%90%A7

com.jfinal.plugin.activerecord.ActiveRecordException: 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 '"z_course_category" set "imgUrl" = '/sassFiles/images/2017/09/12/course_cate_cov' at line 1

at com.jfinal.plugin.activerecord.DbPro.update(DbPro.java:669)

at com.jfinal.plugin.activerecord.DbPro.update(DbPro.java:684)

at com.zhuoyue.service.DbDAL.update(DbDAL.java:52)

at com.zhuoyue.model.sass.BussBackPojo.saveOrUpdateCourseCate(BussBackPojo.java:258)

at com.zhuoyue.controller.sass.BussBackController.addOrUpdateCourseCate(BussBackController.java:361)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.jfinal.aop.Invocation.invoke(Invocation.java:73)

at com.zhuoyue.interceptor.BussDataSource.intercept(BussDataSource.java:51)

at com.jfinal.aop.Invocation.invoke(Invocation.java:67)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:82)

at com.jfinal.plugin.druid.DruidStatViewHandler.handle(DruidStatViewHandler.java:75)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:74)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Unknown Source)

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 '"z_course_category" set "imgUrl" = '/sassFiles/images/2017/09/12/course_cate_cov' at line 1

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)

at com.mysql.jdbc.Util.getInstance(Util.java:387)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:941)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3870)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3806)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2470)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2617)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2550)

at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)

at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)

at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)

at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5094)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)

at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeUpdate(DruidPooledPreparedStatement.java:253)

at com.jfinal.plugin.activerecord.DbPro.update(DbPro.java:294)

at com.jfinal.plugin.activerecord.DbPro.update(DbPro.java:649)

at com.jfinal.plugin.activerecord.DbPro.update(DbPro.java:667)

... 31 more

九月 13, 2017 5:22:32 下午 org.apache.catalina.core.StandardContext reload

信息: Reloading Context with name [/zhuoyue_wc] has started

2017-09-13 17:22:32,285 INFO  [SchedulerPlugin] - SchedulerPlugin is stopped

2017-09-13 17:22:32,315 INFO  [com.alibaba.druid.pool.DruidDataSource] - {dataSource-1} closed

九月 13, 2017 5:22:32 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc



评论区

JFinal

2017-09-14 00:20

异常提示是 sql 写错了,据判断很可能是你传参方式引起的,将 url 问号挂参改为 post 请求体传参

AndrewTseng

2017-09-16 14:36

@JFinal 谢谢波总,已经解决了。

silenceViking

2017-10-12 15:39

@JFinal 波总我在使用Jfinal Db + Record 模式save保存时,不添加主键参数会报错"调用中的无效参数",但是我进入save封装方法 里面确实有不传主键的一个save方法,请问这是什么原因?

JFinal

2017-10-13 11:08

@silenceViking 不指定主键名的时候,默认为 "id",如果不是这个值,需要手动指定,例如:
Db.save("user", "user_id" record);

silenceViking

2017-10-25 16:14

@JFinal 谢谢波总回复,但是如果数据表就没有“id”列,比如:车站大屏信息同步,不需要给车次指定id,每30秒刷新(事务:先删除、再插入)数据。这种重复插入的过程、save方法的id值能不指定吗?

热门反馈

扫码入社