Oracle doesn't remove cursors after closing result set

Posted by Vladimir on Stack Overflow See other posts from Stack Overflow or by Vladimir
Published on 2010-04-01T12:43:27Z Indexed on 2010/04/01 12:53 UTC
Read the original article Hit count: 327

Filed under:
|
|
|
|

Note: we reuse single connection.

************************************************
public Connection connection() {        
       try {
           if ((connection == null) || (connection.isClosed()))
           {
              if (connection!=null) log.severe("Connection was closed !");
               connection = DriverManager.getConnection(jdbcURL, username, password);
           }
       } catch (SQLException e) {
           log.severe("can't connect: " + e.getMessage());
       }
       return connection;        
   }
**************************************************

public IngisObject[] select(String query, String idColumnName, String[] columns) {
Connection con = connection();

Vector<IngisObject> objects = new Vector<IngisObject>();
try {
    Statement stmt = con.createStatement();

    String sql = query;
    ResultSet rs =stmt.executeQuery(sql);//oracle increases cursors count here
    while(rs.next()) {
       IngisObject o = new IngisObject("New Result");
       o.setIdColumnName(idColumnName);            
       o.setDatabase(this);
       for(String column: columns) o.attrs().put(column, rs.getObject(column));
       objects.add(o);
       }

    rs.close();// oracle don't decrease cursor count here, while it's expected
    stmt.close();
    } 
catch (SQLException ex) {
    System.out.println(query);
    ex.printStackTrace();
}

© Stack Overflow or respective owner

Related posts about java

Related posts about Oracle