File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Problem closing PreparedStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem closing PreparedStatement" Watch "Problem closing PreparedStatement" New topic
Author

Problem closing PreparedStatement

Vadim Vararu
Ranch Hand

Joined: Jan 03, 2009
Posts: 147
I've got a connection pool and a class that has 2 methods: executeUpdate and executeQuery. Each of these methods' call uses a connection from the connection pool, a new prepared statement and a new result set. So, functionality is incapsulated in that class. Programmers will know only about xxx.executeUpdate(String query, ArrayList params) and xxx.executeQuery(String query, ArrayList params) that returns a resultSet. I have no problem with update, because i have no result sets at all. The problem is with closing the prepared statement in executeQuery.

Where could i close the prepared statement in the executeQuery? If i close it there in a ordinary way, the result set that should be returned is also closed.

If you think you've done too much, usually it means you've done too few.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You should never return (or expose) ResultSets, you should always convert to a custom object type and return that.
Vadim Vararu
Ranch Hand

Joined: Jan 03, 2009
Posts: 147
David O'Meara wrote:You should never return (or expose) ResultSets, you should always convert to a custom object type and return that.



I know. That's why i return a result set to a CRUD, and than CRUD methods return objects.
Vadim Vararu
Ranch Hand

Joined: Jan 03, 2009
Posts: 147
At least, that's what i am going to do.

Programmer will have classes that implement CRUD and will use result sets to generate objects...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem closing PreparedStatement