mardi 27 juin 2023

Read CLOB from Oracle using JDBC results in random ORA-17002 failure

As part of a Spring Boot application, I am attempting to query an Oracle Enterprise Edition AWS RDS table that contains CLOBs using JDBC. I am using Hakari connection pool and ojdbc8 version 23.2.0.0.

My code is:

Connection conn = null;
    ResultSet rs = null;
    try {
      conn = getConnection();
      PreparedStatement statement = conn.prepareStatement("select id, clobField from myTable");
      rs = statement.executeQuery();
      int recCount = 0;
      while (rs.next()) {
        long id = rs.getLong("id");
        String clob = rs.getString("clobField");
        res.put(id, clob);
        logger.debug("Retrieved record " + ++recCount + ");
      }
    } catch (Exception ex) {
      throw ex;
    } finally {
      if (rs != null) {
        rs.close();
      }
       if (conn != null) {
         conn.close();
       }
    }

The number of records that are successfully retrieved without erroring out is random. When it errors out, I am seeing this error:

java.sql.SQLRecoverableException: ORA-17002: I/O error: An existing connection was forcibly closed by the remote host

Any ideas why this is happening?

This was originally mapped to a spring bean using Hibernate which resulted in the same error. I am trying to isolate the problem, buy decomposing it to just use JDBC.




Aucun commentaire:

Enregistrer un commentaire