| Author |
DataSource VS Connection
|
satishbsk kumar
Greenhorn
Joined: Jul 24, 2009
Posts: 15
|
|
Hi All,
What is the difference between connection obtained by using DataSource and connection got from DriverManager.Which one is effective.
Regards,
Satish
|
 |
Balu Sadhasivam
Ranch Hand
Joined: Jan 01, 2009
Posts: 874
|
|
Satish,
As far as connection itself is concerned , there shouldn't be any difference. However Datasource has several advantages over DriverManager , which should be preferred.
CodePortability
Can be used as JNDI service
enables to maintain Connection pools.
|
 |
Jaydeep Vaishnav
Greenhorn
Joined: Sep 08, 2009
Posts: 16
|
|
|
When we have a scenario of multiple hits on the database at the same time, Datasource is preferrable over the DriverManager. Driver manager reduces the overall performance and can be a bad experience on the client side. While datasource uses connection pooling and manages resouces effectively. Many details are hidden in the statement but as far as the answer to your question is concerned, DataSource should be preffered.
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14456
|
|
Typically, a Connection returned from a DataSource aggregates on a DriverManager Connection opened by the DataSource itself. Almost all the methods on the aggregating connection are passed along to the fronted Connection, with one exception. The close() method returns the Connection to the DataSource connection pool instead of actually closing the connection. That way the Connection will be ready to use when it is again retrieved from the pool. Rigorous implementations will also ensure that before the Connection is handed out again it's reset to a known state, but it's better not to assume that.
This is while it's critical to intercept all JDBC errors and make sure you have explicitly closed all connections, including those where the exception would otherwise fly by the close done by non-error code. Otherwise you'll leak connections.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
satishbsk kumar
Greenhorn
Joined: Jul 24, 2009
Posts: 15
|
|
|
Thanks all for your valuable suggestions..
|
 |
 |
|
|
subject: DataSource VS Connection
|
|
|