关于mybatis的小问题

来源:互联网 发布:linux格式化目录 编辑:程序博客网 时间:2024/06/10 07:15

今天使用mybatis出现了莫名其妙的问题,sql语句竟然出错了,但仔细看却没有错啊


org.springframework.jdbc.BadSqlGrammarException: ### Error updating database.  Cause: 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 'order(trade_no,amount,store_id,file,create_time,pay_time) values('success',2.0,'' at line 1### The error may involve org.zhijingprint.dao.OrderDao.insertOrder-Inline### The error occurred while setting parameters### SQL: insert into order(trade_no,amount,store_id,file,create_time,pay_time) values(?,?,?,?,?,?)### Cause: 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 'order(trade_no,amount,store_id,file,create_time,pay_time) values('success',2.0,'' at line 1; bad SQL grammar []; nested exception is 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 'order(trade_no,amount,store_id,file,create_time,pay_time) values('success',2.0,'' at line 1at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231)at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)at com.sun.proxy.$Proxy14.insert(Unknown Source)at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:279)at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:46)at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)at com.sun.proxy.$Proxy15.insertOrder(Unknown Source)at org.zhijingprint.service.impl.impl.OrderServiceImplTest.addOrder(OrderServiceImplTest.java:33)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:70)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)at org.junit.runners.ParentRunner.run(ParentRunner.java:363)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)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 'order(trade_no,amount,store_id,file,create_time,pay_time) values('success',2.0,'' at line 1at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)at java.lang.reflect.Constructor.newInstance(Constructor.java:423)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:939)at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551)at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:989)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:55)at com.sun.proxy.$Proxy17.execute(Unknown Source)at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:41)at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:66)at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:45)at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:100)at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75)at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:148)at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:137)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)... 34 more

红色字体即为插入语句,我又看了看mybatis的mapper下的配置文件,发现order竟然是蓝色字体(IDE为idea),所以我就修改了表名,发现竟然成功了,然而我想


用order做表名又要怎么做呢?经过多番搜索,终于找到方法,就是在插入语句中的order改为 `order` `符号为英文字符的tab键上面的按键。以后要是遇到表名字体变


蓝,只需要套上 `` 即可


或者在mybatis中用id表示


<sql id="t_order">`order`</sql>



参考:http://www.cnblogs.com/gmq-sh/p/5393654.html(如侵删)

原创粉丝点击