0

We have recently upgraded Oracle database from 11g release2 to 19c.

Now we have Oracle 19c database server, JDK 1.8 and ojdbc6.jar combination.

We have some java code to create JDBC Statement object with scrollable and concurrent read only ResultSet feature. With the mentioned combination JDBC query execution is failing with following error

Approach1:

Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);                   
ResultSet resultSet = statement.executeQuery(query);

Post upgrade statement.executeQuery() method is throwing following Exception

java.sql.SQLRecoverableException: Closed Connection
        at oracle.jdbc.driver.OracleStatement.ensureOpen(OracleStatement.java:4477)
        at oracle.jdbc.driver.OracleStatement.clearWarnings(OracleStatement.java:3430)
        at oracle.jdbc.driver.OracleStatement.prepareForNewResults(OracleStatement.java:3946)
        at oracle.jdbc.driver.OracleStatement.doScrollExecuteCommon(OracleStatement.java:5246)
        at oracle.jdbc.driver.OracleStatement.doScrollStmtExecuteQuery(OracleStatement.java:5302)
        at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1325)
        at oracle.jdbc.driver.OracleStatementWrapper.executeQuery(OracleStatementWrapper.java:422)
        at JDBCConnectionUtilDebug.getQueryOutput(JDBCConnectionUtilDebug.java:294)

But if I run same sql query using following approach, then it works fine

Approach2:

 Statement stat = connection.createStatement();
 boolean ret = stat.execute(query");
 if (ret) {
 ResultSet rs = stat.getResultSet();

Any help/pointer why Approach1 is failing but Approach2 is working?

Kousik Mandal
  • 686
  • 1
  • 6
  • 15
  • 1
    Why are you using ojdbc6? AFAIK, Oracle hasn't released drivers for Java 6 in some time, which means it is probably a pretty old driver. Use a newer version of the driver. Also, please post a [mre]. – Mark Rotteveel Apr 13 '23 at 09:03
  • 1
    Honesty I'd not waste much time with problem like this. ojdbc is intended for Java 1.8. You should use ojdbc8 with JDK 1.8. Also I have doubts about compatibility of any version of ojdb6 with Oracle 19c. The span is too big. Check here https://stackoverflow.com/a/56531594/836215 , "execute" the driver and you will see for which database version this driver is intended. – ibre5041 Apr 13 '23 at 12:08

1 Answers1

0

Thank you both @Mark Rotteveel and @ibre5041 for your response.

As per [What are the Oracle JDBC releases Vs JDK versions?] https://www.oracle.com/in/database/technologies/faq-jdbc.html

The combination 19C database, java 1.8 and ojdbc6.jar is not compatible.

The Oracle JDBC driver is always compliant to the latest JDK version in each of the new releases. In some versions, JDBC drivers support multiple JDK versions. Use the table below to choose the correct JDBC driver based on your preferred JDK version.

Oracle Database version

19.x

JDBC Jar files specific to the release

  • JDBC 4.3 in ojdbc10.jar
  • JDBC 4.2 in ojdbc8.jar

After using ojdbc8.jar instead of ojdbc6.jar both query execution approaches working fine.

Kousik Mandal
  • 686
  • 1
  • 6
  • 15