Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class to handle connections

 
Reggie McDougal
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A question, is it OK to pass my SQL into a DB_Bean that gets the connection
and passes back the resultSet, what about closing the connection, will this happen automatically when the method returns or is this just a bad practice




My method is like so that calls the DB_Bean


Reg
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are not using the DBCP, then you should get the connection when required and close it after use. Moreover you should take care of thread-safety.
[ December 13, 2004: Message edited by: Adeel Ansari ]
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. The connection is not closed automatically. The resultset returned from the method, still maintains a connection to the database.
The RowSet might be an alternative.

Or you have to populate the values from resultset into your own objects and return them instead of returning the resultset (and close the connection in the getRecords() method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic