2 Replies Latest reply on Mar 21, 2005 3:30 PM by davidchen

    should I close resultset explicitly before re-excuted the st

    davidchen Newbie

      Hi, there:

      It might be JDBC question, because I just noticed it when I enable <track-statements> these days, so please bear with me posting it here.
      I'm using jboss-3.2.6, jdk1.4.2, oracle 9i jdbc ojdbc14.jar. My code:

      try{
       ...................
       statement = con.createStatement();
       resultSet = statement.executeQuery(QUERY_VIEW); //line A
       callSomeFunc(resultSet);
       //if(resultSet != null) resultSet.close();
       resultSet = statement.executeQuery(QUERY_TABLE); //line B
       callAnotherFunc(resultSet);
       succeed = true;
      }catch(SQLException se){
       log.error("....");
      }finally {
       try{
       if(resultSet != null) resultSet.close();
       if(statement != null) statement.close();
       if(con != null) con.close();
       }catch(SQLException se){
       log.error(");
       }
      }
      

      At very beginning, I just close statement and con in finally section, which gives me warning information ask me to close resultset myself, so, I added resultSet.close before statement.close(). however, it still gives me warning information to close resultset myself, but this time asked me to close result set created in "line B". So, questions:
      1. Isn't resultset supposed to automatically closed when statement is closed? and closed before retrieving the next result?
      2. Is that oracle jdbc driver issue?
      3. Should I explicitly close resultset before I close the statement and before retrieve the next result?

      from jdk spec, it says:
      A ResultSet object is automatically closed when the Statement object that generated it is closed, re-executed, or used to retrieve the next result from a sequence of multiple results.

      Highly appreciated if any comments. Thanks a lot in advance

      David