zoukankan      html  css  js  c++  java
  • 表字段或表名出现Mysql关键字或保留字导致问题 Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have

    MySQL 5.7使用的关键字和保留字
    https://dev.mysql.com/doc/refman/5.7/en/keywords.html

    当我们建表的时候如果使用了关键字或者保留字,则在执行sql的时候都会报错。错误信息一般都是这样的:
    这里的错误是表明使用了order ,但是在xml中没有使用 ``,改正:在sql中把表明括起来 - order

    org.apache.ibatis.exceptions.PersistenceException: 
    ### Error querying 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 where orderid = 'A01'' at line 1
    ### The error may exist in mapper/taobaomapper.xml
    ### The error may involve defaultParameterMap
    ### The error occurred while setting parameters
    ### SQL: select * from order where orderid = ?
    ### 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 where orderid = 'A01'' at line 1
    
    	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
    	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)
    	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
    	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)
    	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68)
    	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
    	at com.sun.proxy.$Proxy5.findOrderById(Unknown Source)
    	at TaobaoTest.orderTest(TaobaoTest.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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    	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.junit.runners.ParentRunner.run(ParentRunner.java:363)
    	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
    	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
    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 where orderid = 'A01'' at line 1
    	at 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:425)
    	at com.mysql.jdbc.Util.getInstance(Util.java:408)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3970)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
    	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
    	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
    	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
    	at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
    	at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:59)
    	at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:73)
    	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:60)
    	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
    	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
    	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
    	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)
    	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
    	... 29 more
    
    
    Process finished with exit code -1
    
    
  • 相关阅读:
    纯awk传参和awk脚本传参
    【转】MySQL 备份和恢复(MyISAM 和 Innodb)
    【z】多线程Java Socket编程示例
    Java,Tomcat,Mysql乱码总结
    mysql备份与同步shell脚本
    【转】Velocity用户手册中文版(学习修改版)
    wml新学的标签
    【原】小心log4j的多进程写入
    【z】Webservice 的设计和模式
    【z】linux面试题参考答案
  • 原文地址:https://www.cnblogs.com/InternetJava/p/12543183.html
Copyright © 2011-2022 走看看