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

2 simple questions..

Grub de Bliek
Greenhorn

Joined: Sep 09, 2003
Posts: 19
1. When I close my statement and my connection, do I lose the ResultSet I just queried?
2. Look at this piece of code:
//querying code....
} catch(SQLException e) {
e.printStackTrace();
} finally {
if (statement != null)
statement.close();
if (connection != null)
connection.close();
}
}
This can't be done cuz both close() methods must be handled with an SQLException as well. The way I see it is that I *must* catch that SQLException one level higher, but I don't want that. All my exceptions must be handled in this method. Is there a way to solve this?


When the compiler isn't happy, nobody is happy...
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

You want to encapsulate each close() call in their own try/catch blocks so they are each executed even if one throws an exception.


[How To Ask Questions On JavaRanch]
Rudy Dakota
Ranch Hand

Joined: Jul 27, 2002
Posts: 54
Gerben,
the answer to your first question: yes!
Good riding,
Rudy.
Grub de Bliek
Greenhorn

Joined: Sep 09, 2003
Posts: 19
Ok thanks!
I knew I could put a try/catch block in a finally block, but I was thinking that prevented the finally block from executing. I see that isn't correct, if an exception occurs in a finally block, the rest of the code is executed anyway.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 2 simple questions..