When the same query is used in multiple PreparedStatements and the database changes inbetween some statements get invalid.
When StatementManager.compile() finds the same statement with a different compile timestamp it simply removes the old statement instead of trying to recompile it. This leaves the first statement in an invalid state even though it could be recompiled without issues.
I don't see an option to create the statements as independent besides ammending the SQL with an unique comment.
@Test
public void testConnectionIsValid() throws SQLException {
assertNotNull(connection);
Statement stmt = connection.createStatement();
stmt.execute("CREATE TABLE journal(message VARCHAR(255))");
PreparedStatement statement1 = connection.prepareStatement("INSERT INTO journal VALUES (?)");
stmt.execute("CREATE TABLE test1(Id INTEGER)");
PreparedStatement statement2 = connection.prepareStatement("INSERT INTO journal VALUES (?)");
stmt.execute("CREATE TABLE test2(Id INTEGER)");
statement1.setString(1, "finished writing 1");
statement1.execute();
statement1.close();
statement2.setString(1, "finished writing 2");
statement2.execute();
statement2.close();
stmt.close();
}
This happens since version 2.5.2
Thanks for reporting. Please note there have been a lot of changes since version 2.5.2. Please check with version 2.7.4 (either Java 8 or Java 11 jar).
It's happening with 2.7.4 and every version sind 2.5.2
Thank you. I will check this later.
Fixed and committed to SVN (revision 6840)