insert into table values(1,'中文'),数据库的编码和表的编码均是utf-8
在mysql workbench中插入没有问题,就是java中插入时报错,为啥呢?
报错信息:
java.sql.SQLException: Syntax error or access violation, message from server: "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 '' at line 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1825)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1020)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1109)
at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1070)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2027)
at com.mysql.jdbc.Connection.execSQL(Connection.java:1984)
at com.mysql.jdbc.Statement.execute(Statement.java:896)
at cn.com.elaw.callcenter.service.SearchService.addRecord(SearchService.java:111)
at cn.com.elaw.callcenter.service.SearchService.main(SearchService.java:141)
另外,用绑定变量的方式:
String updateSQL = "insert into ccdb.to_queryInfo(humanID) values(?)";
PreparedStatement myPreparedStatement = myConnection.prepareStatement(updateSQL);
// myPreparedStatement.setString(1, AH);
myPreparedStatement.setInt(1, humanID);
不管有没有中文都报错
换了一个包后,插入不报错了,但是插入的数据乱码