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 can resuse the Connection and Resultset Obj Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "can resuse the Connection and Resultset Obj" Watch "can resuse the Connection and Resultset Obj" New topic
Author

can resuse the Connection and Resultset Obj

bhagya patil
Greenhorn

Joined: Oct 14, 2007
Posts: 12
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

Joined: Oct 27, 2005
Posts: 19693
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Eung maeng
Ranch Hand

Joined: Feb 10, 2002
Posts: 68
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,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can resuse the Connection and Resultset Obj