大家好,在开发的时候遇到一个bug,网上找了一些答案但是还没有解决,恳请大家帮忙解决:
环境:MySql5.0.18 JDK:1.6.0_30 JDBC驱动包:mysql-connector-java-5.1.10-bin.jar
Java Code
Statement sql = con.createStatement();
String insertsql = "insert into create_id (id) values('')";
sql.executeUpdate(insertsql);
ResultSet result = sql.getGeneratedKeys();
while (result.next()) {
aid = result.getInt("id");
System.out.println("Aid:"+aid);
}
sql.close();
con.close();
创建表SQL:
CREATE TABLE `create_id` (
`id` BIGINT( 20 ) NOT NULL AUTO_INCREMENT PRIMARY KEY
) ENGINE = MYISAM
异常Bug:
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Out of range value adjusted for column 'id' at row 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3556)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2642)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1647)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1566)
at com.siteview.dao.DBConnection.getaid(DBConnection.java:24)
at com.siteview.dao.DBConnection.main(DBConnection.java:43)
SQLException:Duplicate entry '0' for key 1
已尝试解决方法:1:将表create_id的字段id的长度增加,但不凑效;
2:修改my.ini,将
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"改为
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"。 也没有凑效。
请教大家还有可能是什么原因引起的?谢谢
--转自