Archive

Archive for March, 2010

Operation not allowed after ResultSet closed

March 5, 2010 Leave a comment

Result sets are implicitly closed when the statement that created them are closed. Statements are implicitly closed when the connection that created them are closed.

So it is not advisable to return an ResultSet for the method.

public ResultSet executeDBQuery(){
// try block
//Establish Connection connection = DriverManager.getConnection(url, userName, password);
//Statement st = connection.createStatement();
//resultSet = st.executeQuery(dBQuery);
//ResultSet will not contain any details if the connection is closed.
//Close connection
//return resultSet
}

Alternative :
public ResultSet executeDBQuery(){
// try block
//Establish Connection connection = DriverManager.getConnection(url, userName, password);
//Statement st = connection.createStatement();
//resultSet = st.executeQuery(dBQuery);
//do not close the connection
//return resultSet
}

ResultSet rs = DB..executeDBQuery()
//Now Close the connection

-Ram

Advertisements
Categories: Uncategorized