File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Clone DBConnection Object

Shankar sanjay
Ranch Hand

Joined: Sep 14, 2009
Posts: 117

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

Joined: Aug 22, 2010
Posts: 3732

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:
subject: Clone DBConnection Object
It's not a secret anymore!