讨教一下各位,本人在Mysql里面建的表中name字段的编码是utf8,建立数据库连接也指定了编码方式:
jdbc:mysql://10.136.34.158:3306/zjgis?useUnicode=true&characterEncoding=GBK
现在本人要用java把字符串“康富美实业有限公司支现叩涫饺鄱掀”插入mysql的表中,程序执行抛异常:
java.sql.BatchUpdateException: Incorrect string value: “\xAC\xE5\x8F\xB8\xE6\x94…” for column “NAME” at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2054)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1467)
at com.creaway.pms20.datacenter.doTransToMySQL.executeInsertBatch(doTransToMySQL.java:455)
at com.creaway.pms20.datacenter.doTransToMySQL.doInsert(doTransToMySQL.java:437)
at com.creaway.pms20.datacenter.doTransToMySQL.transTable(doTransToMySQL.java:379)
at com.creaway.pms20.datacenter.TransToMySQL.doTransPsr(TransToMySQL.java:343)
at com.creaway.pms20.datacenter.TransToMySQL.main(TransToMySQL.java:12)
Caused by: java.sql.SQLException: Incorrect string value: “\xAC\xE5\x8F\xB8\xE6\x94…” for column “NAME” at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2006)
… 6 more
问一下各位该怎么样解决?
jdbc:mysql://10.136.34.158:3306/zjgis?useUnicode=true&characterEncoding=GBK
现在本人要用java把字符串“康富美实业有限公司支现叩涫饺鄱掀”插入mysql的表中,程序执行抛异常:
java.sql.BatchUpdateException: Incorrect string value: “\xAC\xE5\x8F\xB8\xE6\x94…” for column “NAME” at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2054)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1467)
at com.creaway.pms20.datacenter.doTransToMySQL.executeInsertBatch(doTransToMySQL.java:455)
at com.creaway.pms20.datacenter.doTransToMySQL.doInsert(doTransToMySQL.java:437)
at com.creaway.pms20.datacenter.doTransToMySQL.transTable(doTransToMySQL.java:379)
at com.creaway.pms20.datacenter.TransToMySQL.doTransPsr(TransToMySQL.java:343)
at com.creaway.pms20.datacenter.TransToMySQL.main(TransToMySQL.java:12)
Caused by: java.sql.SQLException: Incorrect string value: “\xAC\xE5\x8F\xB8\xE6\x94…” for column “NAME” at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2006)
… 6 more
问一下各位该怎么样解决?
解决方案
40
把characterEncoding=GBK改成utf8试试吧