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 有可能是使用的关键字,切记切记

  • 33
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

涛声依旧Cjt

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值