wood burning stoves 2.0*
The moose likes Java in General and the fly likes Clone DBConnection Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Clone DBConnection Object " Watch "Clone DBConnection Object " New topic
Author

Clone DBConnection Object

Shankar sanjay
Ranch Hand

Joined: Sep 14, 2009
Posts: 117
Hi,


I understand that Deep copy (clone) will return new separate object. So I am thinking like this..

i will create a DB connection object(say dbConnection) while my application start up, and stored it in cache. After that, whenever data base connection require then i will get a clone of dbConnection and try to process further.

can you please advice, this will be a good approach?

Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

This (most probably) is not going to work. Not all objects are cloneable. A database connection has to be established by calling the database server and it keeps some communication channel to the database open, these things from their very nature are not cloneable.

That said, a database connection might implement the Clonable interface and make sure to actually open a new connection when cloned, however I'd say no JDBC driver does so. It does not make much sense. A Connection Pool is usually used to re-use connection resources.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clone DBConnection Object
 
Similar Threads
Problem when trying to instanciate a Bean ->
wondering with RMI server!
JDBC beginner doubt
Singleton Connection Class
How to close the server properly?