一次 Mysql 字符集的报错,最后让我万马奔腾!!!

wuba---深圳---龙岗周边---2000-3000元---29---20180121---28657
wuba---深圳---龙岗周边---3000-5000元---29---20180121---28658
wuba---深圳---龙岗周边---5000-8000元---37---20180121---28659
wuba---深圳---龙岗周边---600-1000元---27---20180121---28660
wuba---深圳---龙岗周边---600元以下---25---20180121---28661
wuba---深圳---龙岗周边---8000元以上---36---20180121---28662
Mon Jan 22 17:43:14 CST 2018Insert Danke check data inserted
java.sql.BatchUpdateException: 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 'range,num) values('20180121','wuba','深圳','龙岗周边','8000元以上',36)' at line 1
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2055)
    at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1467)
    at util.InsertIntoMysql.InsertDankeCheck(InsertIntoMysql.java:224)
    at Info.Xx_Danke.Xx_DankeRank(Xx_Danke.java:103)
    at Info.Xx_Danke.main(Xx_Danke.java:117)
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 'range,num) values('20180121','wuba','深圳','龙岗周边','8000元以上',36)' at line 1
    at sun.reflect.GeneratedConstructorAccessor2.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.Util.getInstance(Util.java:386)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2617)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2778)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2825)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2156)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2459)
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2007)
    ... 4 more

开始以为是字符集的错误,各种找原因,看JDBC连接参数。。。

试了N种方法之后,直接用代码传入定值,结果依旧。当时马上就知道了,表出问题了。。。

复制了一个可以用的表,然后改结构,重试。依然报这个错。

再复制insert语句到navicat中,结果还是报错。。。 目标定到了我的‘’range‘’字段

insert into danke_check(day,site,city,street,range,num) values ('2017-10-20','anjuke','深圳','龙门县','500-8000元',20)



insert into danke_check(day,site,city,street,range_num,num) values ('2017-10-20','anjuke','深圳','龙门县','500-8000元',20)

当时range字段是蓝色字体,好像心里就明白了。

把range改成range_num  插入完成。

顿时,万马奔腾!!!!!!!!!!!!!!!不是第一次了,也差不多是第二次了,range是关键词!!!!!

2018年1月23日10:14:13

记录一下

原文地址:https://www.cnblogs.com/tnsay/p/8334234.html