title: Closed Connection: next in java
body: <p>I have ResultSet Methods which I am closing the Connection in a finallly Block:</p>
  
  <pre><code> public static ResultSet countdrcountcr(String vforacid) throws SQLException {
          ResultSet rs = null;
          Connection conn = null;
          try {
  
              conn = db.getDbConnection();
              String sql = "SELECT NVL (SUM (DECODE (part_tran_type, 'D', 1, 0)), 0), "
                      + " NVL (SUM (DECODE (part_tran_type, 'C', 1, 0)), 0) "
                      + " FROM tbaadm.htd WHERE acid IN (SELECT acid "
                      + " FROM tbaadm.gam WHERE foracid = '" + vforacid + "') "
                      + " AND tran_date &gt;= '22-NOV-2013'  AND tran_date &lt;= '30-NOV-2013' "
                      + " AND pstd_flg = 'Y' AND del_flg != 'Y'";
              PreparedStatement ps = conn.prepareStatement(sql);
              rs = ps.executeQuery();
  
              return rs;
          } finally {
              conn.close();
          }
      }
  </code></pre>
  
  <p>But I am getting the error :</p>
  
  <p><strong>edit The whole ErrorTrace</strong></p>
  
  <pre><code>Exception in thread "main" java.sql.SQLException: Closed Connection: next
  at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
  at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
  at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:181)
  at statement.Statement.main(Statement.java:34)
  Java Result: 1
  </code></pre>
  
  <p>What am I not doing right?</p>