Home > Uncategorized > Operation not allowed after ResultSet closed

Operation not allowed after ResultSet closed

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
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: