Description:
The doc of getWarings method in StatementImpl says that "The warning chain is automatically cleared each time a statement is (re)executed". But it's not actually. I don't know it's a bug or ducument wrong.
How to repeat:
Here is the test case, it will create two tables fist run without log, but second time it will print duplicate log as below, the table1 warning log twice.
SQLWarning ignored: SQL state '42S01', error code '1050', message [Table 'table1' already exists]
SQLWarning ignored: SQL state '42S01', error code '1050', message [Table 'table1' already exists]
SQLWarning ignored: SQL state '42S01', error code '1050', message [Table 'table2' already exists]
String sql1 = "CREATE TABLE IF NOT EXISTS `table1`(`id` bigint unsigned);";
String sql2 = "CREATE TABLE IF NOT EXISTS `table2`(`id` bigint unsigned);";
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/lfz", "root", "root");
Statement statement = connection.createStatement();
statement.execute(sql1);
SQLWarning warningToLog = statement.getWarnings();
while (warningToLog != null) {
System.out.println(("SQLWarning ignored: SQL state '" + warningToLog.getSQLState() +
"', error code '" + warningToLog.getErrorCode() +
"', message [" + warningToLog.getMessage() + "]"));
warningToLog = warningToLog.getNextWarning();
}
statement.execute(sql2);
warningToLog = statement.getWarnings();
while (warningToLog != null) {
System.out.println(("SQLWarning ignored: SQL state '" + warningToLog.getSQLState() +
"', error code '" + warningToLog.getErrorCode() +
"', message [" + warningToLog.getMessage() + "]"));
warningToLog = warningToLog.getNextWarning();
}
Description: The doc of getWarings method in StatementImpl says that "The warning chain is automatically cleared each time a statement is (re)executed". But it's not actually. I don't know it's a bug or ducument wrong. How to repeat: Here is the test case, it will create two tables fist run without log, but second time it will print duplicate log as below, the table1 warning log twice. SQLWarning ignored: SQL state '42S01', error code '1050', message [Table 'table1' already exists] SQLWarning ignored: SQL state '42S01', error code '1050', message [Table 'table1' already exists] SQLWarning ignored: SQL state '42S01', error code '1050', message [Table 'table2' already exists] String sql1 = "CREATE TABLE IF NOT EXISTS `table1`(`id` bigint unsigned);"; String sql2 = "CREATE TABLE IF NOT EXISTS `table2`(`id` bigint unsigned);"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/lfz", "root", "root"); Statement statement = connection.createStatement(); statement.execute(sql1); SQLWarning warningToLog = statement.getWarnings(); while (warningToLog != null) { System.out.println(("SQLWarning ignored: SQL state '" + warningToLog.getSQLState() + "', error code '" + warningToLog.getErrorCode() + "', message [" + warningToLog.getMessage() + "]")); warningToLog = warningToLog.getNextWarning(); } statement.execute(sql2); warningToLog = statement.getWarnings(); while (warningToLog != null) { System.out.println(("SQLWarning ignored: SQL state '" + warningToLog.getSQLState() + "', error code '" + warningToLog.getErrorCode() + "', message [" + warningToLog.getMessage() + "]")); warningToLog = warningToLog.getNextWarning(); }