aspose file tools
The moose likes Java in General and the fly likes try...catch...finally w/ a result set Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "try...catch...finally w/ a result set" Watch "try...catch...finally w/ a result set" New topic
Author

try...catch...finally w/ a result set

Paul Wetzel
Ranch Hand

Joined: Nov 02, 1999
Posts: 107
I am using a ResultSet and would like to make sure i close it and set to null when done.
I would like to do something along the lines of the following:
ResultSet rs;
try
{
...
rs = theStatement.executeQuery(sqlStmt);
}
catch (Exception ex)
{
...
}
finally
{
if (rs != null)
{
rs.close();
rs = null;
}
}
problem is I get an compile error that rs might not have been initialized. I cannot declare/instantiate rs outside of the try since it is an interface (ResultSet rs = new ResultSet() NOT LEGEL!). How do I do this :}
thanks in advance
paul wetzel
------------------
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
Change the first line to:
<pre> ResultSet rs = null;</pre>
That's sufficient for it to be "initialized" as far as the compiler is concerned.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: try...catch...finally w/ a result set
 
Similar Threads
Closing ResultSet questions
Null error
Optimal JDBC connection pooling configuration for tomcat server
idiom for finally closing resources
interfaces