aspose file tools
The moose likes Java in General and the fly likes Using Resultset object Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Using Resultset object" Watch "Using Resultset object" New topic
Author

Using Resultset object

Sahil Sharma
Ranch Hand

Joined: Aug 27, 2003
Posts: 152
Hi

Can i use resultset object after the connection and statement objects are closed. I am using Java/Mysql.

Currently I am getting an error when i try to use my resultset object after closing my connection and statement

Error: java.sql.SQLException: Operation not allowed after ResultSet closed
~thnx
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1008
>Can i use resultset object after the connection and statement objects are closed?
No.

If you close a statement it closes all its child result sets.
If you close a connection it closes all its child statements (and thus the result sets)

However good code should not rely on this. You should explicitly close all of your result sets, statements and connections (in that order)
Sahil Sharma
Ranch Hand

Joined: Aug 27, 2003
Posts: 152
when do we get Too Many Connections exception ?.
When connection objects are not closed ?
Do we also get this error when dont close resultsets objects explicitly ?
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
This sounds like something that would be useful for you to solve yourself:

1. Write a loop that opens lots of connections.
To keep them from being garbage collected, put them
in an array or Collection.

2. Write a loop that: opens a connection, creates a statement
and executes a simple query, like SELECT * FROM sometable,
and stores the ResultSet in an array or Collection. Then
close the Connection.

What is your conclusion?


There is no emoticon for what I am feeling!
Adam Richards
Ranch Hand

Joined: Nov 03, 2005
Posts: 133
This sounds like a bug. I'd look for connections being continually opened without old ones being closed. My own personal style is that once I open a connection, I keep it open as long as possible, until I'm done using it, then explicitlyi close it.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Stefan Evans:

However good code should not rely on this. You should explicitly close all of your result sets, statements and connections (in that order)


Why?

Anyway, moving to JDBC forum...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Using Resultset object
 
Similar Threads
How to close ResultSet in a function after returning it
ResultSet is closed??
Using Resultset object
Connection, Resultset and statement
ResultSet closed error (URGENT !!)