Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DataSource VS Connection

 
satishbsk kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
satishbsk kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for your valuable suggestions..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic