Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can resuse the Connection and Resultset Obj

 
bhagya patil
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we reuse the only one existing Connection and one Resultset Obj to run more than one sql queries?
or every time when we need to get new connction object n rs object and run different the queries and close connection and resultset?
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The connection can be reused as much as you want, just don't close it. Do keep in mind that if every client has an idle connection it may decrease performance on the database server. There is an increase in performance on the client though since you don't have to reconnect all the time. Whether or not you want to have idle connections is up to you.

As for result sets, these may be shared by the SQL driver, but you shouldn't reuse the objects yourself - always close result sets and statements as soon as you no longer need them. This doesn't mean you can't reuse the reference variables though.
 
Eung maeng
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder how to keep the connection when external program will request to connect several time.
for example, A.class calls b.class(where JDBC connection to DB2 database) many times per day. In this case, if I don't keep the connection from B.class, i must be connected for every transaction from A.class's request.

Thus, the performance should be slower down.

please recommand what the best way is.

Regards,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic