}
static void testUpdateDeleteWarning() throws SQLException {
Statement stmt = conn.createStatement();
stmt.executeUpdate("update t2 set c1 = 2 where c1 = 1");
SQLWarning sw = stmt.getWarnings();
if (sw != null)
System.out.println("TEST FAILED! The update should not return a warning.");
stmt.executeUpdate("update t2 set c1 = 2 where c1 = 1");
sw = stmt.getWarnings();
String state, msg;
if (sw == null)
System.out.println("TEST FAILED! The update should return a warning.");
else
{
state = sw.getSQLState();
if (! state.equals("02000"))
System.out.println("TEST FAILED! Wrong sql state.");
msg = sw.getMessage();
if (! msg.startsWith("No row was found for FETCH, UPDATE or DELETE"))
System.out.println("TEST FAILED! Wrong message: " + msg);
}
stmt.executeUpdate("delete from t2 where c1 = 2");
sw = stmt.getWarnings();
if (sw != null)
System.out.println("TEST FAILED! The delete should not return a warning.");
stmt.executeUpdate("delete from t2 where c1 = 2");
sw = stmt.getWarnings();
if (sw == null)
System.out.println("TEST FAILED! The delete should return a warning.");
else
{
state = sw.getSQLState();
if (! state.equals("02000"))
System.out.println("TEST FAILED! Wrong sql state.");
msg = sw.getMessage();
if (! msg.startsWith("No row was found for FETCH, UPDATE or DELETE"))
System.out.println("TEST FAILED! Wrong message: " + msg);
}
stmt.executeUpdate("delete from t3");
sw = stmt.getWarnings();
if (sw == null)
System.out.println("TEST FAILED! The delete cascade should return a warning.");
else
{
state = sw.getSQLState();
if (! state.equals("02000"))
System.out.println("TEST FAILED! Wrong sql state.");
msg = sw.getMessage();
if (! msg.startsWith("No row was found for FETCH, UPDATE or DELETE"))
System.out.println("TEST FAILED! Wrong message: " + msg);
}
}