1 Reply Latest reply on Feb 10, 2004 3:25 PM by jorgewf

    PreparedStatement rset.getStatement() ?

    xav

      Hi,

      In the following simplified code the line stmt = rset.getStatement() doesn't return the PreparedStatement I would like to close (but returns a unknown statement).
      So I'm getting the freezing warning "Closing a statement you left open, please do your own housekeeping" when executing conx.close(), since I didn't close the PreparedStatement.
      Executing pstmt.close() within the finally blocks effectively close the PrepareStatement, but I wouldn't like to do that since all our code has been writen using the ElementosConexao.fecharResultSet() method in order to do so.
      Is it legal to execute in Java stmt = rset.getStatement() in order to get a PreparedStatement, or is it a JBoss or Informix (since we're using it) issue?
      Thanks a lot.

      try {
      pstmt = conx.prepareStatement(...);
      pstmt.setInt(1, ...);
      pstmt.setString(2, ...);
      rset = pstmt.executeQuery();
      }

      finally {
      ElementosConexao.fecharResultSet(rset, true);
      conx.close();
      }


      public static void fecharResultSet(ResultSet rset, boolean fecharStatement){
      Statement stmt = null;

      if (fecharStatement) {
      stmt = rset.getStatement();
      }
      rset.close();
      stmt.close();
      }

        • 1. Re: PreparedStatement rset.getStatement() ?
          jorgewf

          Xav,

          The situation you explained occurs because when you create a statement using a connection you obtained from a JBoss data source, the statement returned to you is an instance of WrappedStatement, but when you execute a query, the instance returned to you is the ResultSet of the JDBC driver you are using, so, when you call rset.getStatement(), the statement returned to you is an instance of the Statement of your driver, not the WrappedStatement.

          Now I have the following question/suggestion:

          Isn´t it suitable to create a class, for instance, WrappedResultSet, to encapsulate any JBoss specific operation on ResultSets, like obtaining the WrappedStatement instead of the driver's Statement?

          Is it a bug or a suggestion? Can I post it in SourceForge?