aspose file tools*
The moose likes JDBC and the fly likes NEED FOR CONNECTION OBJECT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "NEED FOR CONNECTION OBJECT" Watch "NEED FOR CONNECTION OBJECT" New topic
Author

NEED FOR CONNECTION OBJECT

Balaguru Krish
Greenhorn

Joined: Sep 23, 2005
Posts: 9
For iterating a resultset , why there is a need for a connection object after the resultset is being returned by executeQuery(sqlQuery) ?

ResultSet rs = stmt.executeQuery("select * from emp");
con.close();
while( rs.next() )
{

}

It throws an Exception .
Why?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

For your information, writing completely in capital letters is 'shouting' and is often considered rude.

ResultSets do not read all of the results from the query, and they need the Connection so that they are able to go back and read more results when required.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: NEED FOR CONNECTION OBJECT