top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Java: What is the difference between DriverManager.getConnection and DataSource.getConnection

+2 votes
907 views
Java: What is the difference between DriverManager.getConnection and DataSource.getConnection
posted Apr 10, 2014 by Prasad

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

If we assume a (basic) DataSource (that is: one that does not do connection pooling), then you obtain a physical connection that is the same as one obtained from DriverManager (some drivers even internally use DriverManager from the DataSource, or a DataSource from DriverManager). So those connections will behave identically.

Now if we assume a DataSource that provides connection pooling, then the DataSource itself uses a ConnectionPoolDataSource (or a similar internal mechanism) to obtain a PooledConnection. This PooledConnection manages the actual physical connection to the database.

When a user requests a connection from the DataSource, the DataSource will checkout a PooledConnection, and ask it for a Connection. The PooledConnection will then create a logical connection that uses or wraps the physical connection (eg using a Proxy). The DataSource will return that logical connection to the user.

I hope this is the one which you were looking at ...

Source: http://stackoverflow.com/questions/12541005/connection-behavior-drivermanager-getconnection-and-datasource-getconnection

answer Apr 10, 2014 by anonymous
...