开发者

Can I ignore or suppress warnings in JDBC for MySQL?

开发者 https://www.devze.com 2023-01-13 06:14 出处:网络
I have an INSERT INTO ... ON DUPLICATE KEY UPDATE ... statement that executes fine (but with warnings) in the mysql> prompt:

I have an INSERT INTO ... ON DUPLICATE KEY UPDATE ... statement that executes fine (but with warnings) in the mysql> prompt:

mysql> INSERT INTO ... ON DUPLICATE KEY UPDATE ... ;
Query OK, 2 rows affected, 2 warnings (0.00 sec)
Warning (Code 1364): Field 'x' doesn't have a default value

However, when I try to execute the same statement via JDBC the warning shows up as an SQLException and no rows are updated:

java.sql.SQLException: Field 'x' doesn't have a default value
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3536)
  at com.mysql开发者_运维技巧.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3468)  
  at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1957)
  at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)
  at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
  at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2086)
  at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1365)

Is there a JDBC or mysql connector setting or command to ignore or suppress these warnings?

I'm using MySQL Community Server 5.1.31 with MySQL connector 5.1.8 and Java 1.5.0_24.


You can use INSERT IGNORE to suppress these completely.

0

精彩评论

暂无评论...
验证码 换一张
取 消