MYSQL错误Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; --- “signal”

 如题:在项目运行中遇到了类似的错误,仔细检查了个遍,发现写的SQL语句是没有问题的,但是偏偏就报错误,非常的郁闷,贴出我的错误提示。

就在我纠结郁闷的时候,突然灵机一动,修改了其中的某个字段名“signal”,居然奇迹般的就不报错了,能正常的运行了,于是突然意识到,这个错误我使用了某个MYSQL的关键字导致的,于是跑到官网去看,真的被我看到使用了此关键字。

MYSQL关键字查询 : https://dev.mysql.com/doc/refman/5.7/en/keywords.html#keywords-in-current-series

2019-04-11 18:18:39.027  INFO 17862 --- [ool-3-thread-11] com.cjt.nbadmin.service.DeviceService    : 保存设备电量信号信息 : DeviceStatus{id='e9c044bec708454b9f7cbc39c23d216a', token='B57C5AF4C19E460D8B470E72D6A5CFEB', battery=20, signal=19, switchState=0, deviceTime='2019-04-11 18:18:00', reportTime='2019-04-11 18:18:39', delFlag=0}
Exception in thread "pool-3-thread-11" org.springframework.jdbc.BadSqlGrammarException: 
### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: 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 'signal , switch_state , device_time , report_time , del_flag)
      VALUES ('e9c' at line 1
### The error may exist in class path resource [mybatis/mapper/DeviceMapper.xml]
### The error may involve com.cjt.nbadmin.mapper.DeviceMapper.saveDeviceStatus-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO tbl_device_status (id , token , battery , signal , switch_state , device_time , report_time , del_flag)       VALUES (? , ? , ? , ?, ? , ? , ?, ?)
### Cause: java.sql.SQLSyntaxErrorException: 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 'signal , switch_state , device_time , report_time , del_flag)
      VALUES ('e9c' at line 1
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: 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 'signal , switch_state , device_time , report_time , del_flag)
      VALUES ('e9c' 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.$Proxy56.insert(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
	at com.sun.proxy.$Proxy57.saveDeviceStatus(Unknown Source)
	at com.cjt.nbadmin.service.DeviceService.saveDeviceStatus(DeviceService.java:75)
	at com.cjt.nbadmin.coap.CoapHandleThread.handleDeviceStatus(CoapHandleThread.java:321)
	at com.cjt.nbadmin.coap.CoapHandleThread.process(CoapHandleThread.java:124)
	at com.cjt.nbadmin.coap.CoapHandleThread.run(CoapHandleThread.java:52)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLSyntaxErrorException: 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 'signal , switch_state , device_time , report_time , del_flag)
      VALUES ('e9c' at line 1
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:970)
	at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:387)
	at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
	at org.apache.ibatis.executor.ReuseExecutor.doUpdate(ReuseExecutor.java:52)
	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)
	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)
	... 12 more

MYSQL错误Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; --- “signal”_第1张图片

所以下次出现这个错误的时候,如果真的不是语法拼写错误的话,可以看看是不是使用了MYSQL的关键字。

Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax 有可能是使用的关键字,切记切记

你可能感兴趣的:(MySql)