Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem closing PreparedStatement

 
Vadim Vararu
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should never return (or expose) ResultSets, you should always convert to a custom object type and return that.
 
Vadim Vararu
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic