I have the following code block and when the ALTER SESSION
statement is executed, it either hangs or it throws an ORA-01013 depending on whether we're connecting to Oracle 12r2 or 19.3 and what version of the OJDBC8 driver is being used:
try(Connection connection = jdbcConnection.connect(false)) {
// We now have a java.sql.Connection open to the database at this point
try(PreparedStatement ps = connection.prepareStatement(someQuery)) {
// We not have a prepared statement based on query, the query is irrelevent
try (Statement s = connection.createStatement()) {
// The following statement fails with the ORA-01013 error
s.execute("ALTER SESSION SET CONTAINER=" + pdbName);
}
}
}
If I rework this code block to the following, the problem disappears.
try(Connection connection = jdbcConnection.connect(false)) {
// We now have a java.sql.Connection open to the database at this point
try (Statement s = connection.createStatement()) {
s.execute("ALTER SESSION SET CONTAINER=" + pdbName);
}
try(PreparedStatement ps = connection.prepareStatement(someQuery)) {
// We not have a prepared statement based on query, the query is irrelevent
}
// or put the alter session here
}
From what I can determine, using Oracle OJDBC8 12.2.0.1, the hang nor the ORA-01013 exception is thrown; however when I migrate to 19.x.0.0, this is where I'm seeing this problem occur.
Is this a bug in the JDBC driver or is there actually a problem with how the code is written that the 12.2.0.1 driver is more lenient with than the later versions?