Connections vs DataSources

From docs:

A factory for connections to the physical data source that this DataSource object represents. An alternative to the DriverManager facility, a DataSource object is the preferred means of getting a connection.

Actually, a DataSource is a provider of Connections and it has a variety of implementations which operate in different manners. Such as:

  1. Basic implementation -- produces a standard Connection object

  2. Connection pooling implementation -- produces a Connection object that will automatically participate in connection pooling. This implementation works with a middle-tier connection pooling manager.

  3. Distributed transaction implementation -- produces a Connection object that may be used for distributed transactions and almost always participates in connection pooling. This implementation works with a middle-tier transaction manager and almost always with a connection pooling manager.


Connection is the connection :) DataSource is a manager of connections (pool of connections).

Tags:

Java

Jdbc