先说结论:
因为在表设计中有一个商品描述字段被设置为desc,但desc是mysql中的关键字,如select id,name,desc,price from product;这条sql语句在查询时的sql语句解析会和期望的不一样,导致出现问题。因为平时在写java代码的时候很自然的会将描述变量设置为desc,在设计表字段时也没有多想,忘记和忽略了desc为mysql中的关键字,酿成此问题。
排查思路:
一开始怀疑是因为sql过长,删了一部分,成功了,加上又失败了,而且一直提示在price那里只打印了一半pric所以怀疑是不是price那里有问题。去掉price还是报错,最后一个字段一个字段的删减,最后发现是因为使用了sql关键字,desc,作为表字段造成的。
解决方式:
将商品描述列字段名称由desc修改为description。
总结问题:
在设计表字段时千万不可以使用Mysql中已定义的关键字。
异常日志见下:
- org.springframework.jdbc.BadSqlGrammarException:
- ### 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 'desc,site_code,erp_code,model,pack_length,pack_width,pack_height,pack_weight,pri' at line 1
- ### The error may exist in yourpackage/dao/ProductSkuMapper.java (best guess)
- ### The error may involve yourpackage.dao.ProductSkuMapper.selectOneByExample-Inline
- ### The error occurred while setting parameters
- ### SQL: SELECT id,sku_id,product_id,name,marketing_name,sub_title,short_desc,desc,site_code,erp_code,model,pack_length,pack_width,pack_height,pack_weight,price,other FROM product_sku WHERE ( sku_id = ? and status = ? )
- ### 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 'desc,site_code,erp_code,model,pack_length,pack_width,pack_height,pack_weight,pri' 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 'desc,site_code,erp_code,model,pack_length,pack_width,pack_height,pack_weight,pri' at line 1
-
-
- SELECT id,sku_id,product_id,name,marketing_name,sub_title,short_desc,desc,site_code,erp_code,model,pack_length,pack_width,pack_height,pack_weight,price,other FROM product_sku WHERE ( sku_id = 'a21' and status = 0 );
-
- SELECT price,other FROM product_sku WHERE ( sku_id = 'a21' and status = 0 );
-
-
-
-
- 2018-08-30 21:20:40.327 INFO 10008 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1,rm_product} inited
- 2018-08-30 21:20:40.405 DEBUG 10008 --- [ main] n.r.m.p.d.P.selectOneByExample : ==> Preparing: SELECT id,sku_id,product_id,name,marketing_name,sub_title,short_desc,desc,site_code,erp_code,model,pack_length,pack_width,pack_height,pack_weight,price,other FROM product_sku WHERE ( sku_id = ? and status = ? )
- 2018-08-30 21:20:40.425 DEBUG 10008 --- [ main] n.r.m.p.d.P.selectOneByExample : ==> Parameters: a21(String), 0(Integer)
- 2018-08-30 21:20:40.542 ERROR 10008 --- [ main] druid.sql.Statement : {conn-10005, pstmt-20000} execute error. select id, sku_id, product_id, name, marketing_name
- , sub_title, short_desc, desc, site_code, erp_code
- , model, pack_length, pack_width, pack_height, pack_weight
- , price, other
- from product_sku
- where sku_id = 'a21'
- and status = 0
-
- 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 'desc,site_code,erp_code,model,pack_length,pack_width,pack_height,pack_weight,pri' 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:3973)
- at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
- at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
- at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
- at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2487)
- at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
- at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197)
- at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3409)
- at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440)
- at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3407)
- at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440)
- at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3407)
- at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:167)
- at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:498)
- 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:59)
- at com.sun.proxy.$Proxy121.execute(Unknown Source)
- at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:63)
- at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
- at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)
- at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
- at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
- at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
- at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:143)
- at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
- at com.sun.proxy.$Proxy119.query(Unknown Source)
- at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
- at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
- at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
- 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:433)
- at com.sun.proxy.$Proxy87.selectOne(Unknown Source)
- at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166)
- at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
- at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
- at com.sun.proxy.$Proxy101.selectOneByExample(Unknown Source)
- at yourpackage.impl.ProductSkuServiceImpl.getSkuInfoById(ProductSkuServiceImpl.java:89)
- 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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
- at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)
- at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
- at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
- at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
- at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
- at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
- at com.sun.proxy.$Proxy102.getSkuInfoById(Unknown Source)
- at ProductSkuApiTest.getSkuInfoById(ProductSkuApiTest.java:93)
- 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.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
- at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
- 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:84)
- at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
- 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:190)
- 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)
-
- 2018-08-30 21:20:40.550 INFO 10008 --- [ main] o.s.b.f.xml.XmlBeanDefinitionReader : Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
- 2018-08-30 21:20:40.565 INFO 10008 --- [ main] o.s.jdbc.support.SQLErrorCodesFactory : SQLErrorCodes loaded: [DB2, Derby, H2, HDB, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
-
- org.springframework.jdbc.BadSqlGrammarException:
- ### 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 'desc,site_code,erp_code,model,pack_length,pack_width,pack_height,pack_weight,pri' at line 1
- ### The error may exist in yourpackage/dao/ProductSkuMapper.java (best guess)
- ### The error may involve yourpackage.dao.ProductSkuMapper.selectOneByExample-Inline
- ### The error occurred while setting parameters
- ### SQL: SELECT id,sku_id,product_id,name,marketing_name,sub_title,short_desc,desc,site_code,erp_code,model,pack_length,pack_width,pack_height,pack_weight,price,other FROM product_sku WHERE ( sku_id = ? and status = ? )
- ### 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 'desc,site_code,erp_code,model,pack_length,pack_width,pack_height,pack_weight,pri' 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 'desc,site_code,erp_code,model,pack_length,pack_width,pack_height,pack_weight,pri' at line 1
-
- at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:234)
- at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
- at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
- at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
- at com.sun.proxy.$Proxy87.selectOne(Unknown Source)
- at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166)
- at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
- at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
- at com.sun.proxy.$Proxy101.selectOneByExample(Unknown Source)
- at yourpackage.impl.ProductSkuServiceImpl.getSkuInfoById(ProductSkuServiceImpl.java:89)
- 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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
- at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)
- at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
- at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
- at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
- at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
- at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
- at com.sun.proxy.$Proxy102.getSkuInfoById(Unknown Source)
- at ProductSkuApiTest.getSkuInfoById(ProductSkuApiTest.java:93)
- 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.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
- at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
- 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:84)
- at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
- 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:190)
- 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 'desc,site_code,erp_code,model,pack_length,pack_width,pack_height,pack_weight,pri' 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:3973)
- at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
- at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
- at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
- at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2487)
- at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
- at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197)
- at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3409)
- at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440)
- at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3407)
- at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440)
- at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3407)
- at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:167)
- <
原文:https://blog.csdn.net/lingyejun/article/details/121646931
ERP
联系站长
QQ:769220720