Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connections vs DataSources

Tags:

java

jdbc

I am reading about Connections vs DataSources in Java and I have some questions. Is a DataSource really just a manager and an abstraction of a Connection (or multiple connections)?

like image 795
LuckyLuke Avatar asked Mar 03 '13 16:03

LuckyLuke


People also ask

What is the difference between DataSource and connection pool?

A data source (resource, since this could also be a JMS queue or topic) has a connection pool. This allows a J2EE application to reuse connections versus creating a new connection every time. There are XA and non-XA data sources. A non-XA data source is also known as a 1pc (one phase commit) data source.

What is the difference between data source and connection in Tableau?

A Tableau data source may contain multiple data connections to different databases or files. Connection information includes where the data is located, such as a file name and path or a network location, and details on how to connect to your data, such as database server name and server sign-in information.

What is the difference between DriverManager and DataSource?

DataSource and the DriverManager are the two basic ways to connect to a database. The DriverManager is older facility, DataSource is newer. It is recommended to use the new DataSource facility to connect to databases and other resources.

What is a data source connection?

A data source connection specifies the parameters needed to connect to a database, such as the location of the database and the timeout duration. These parameters form a connection string for the data source. You can include authentication information for the database in the data source connection by creating a signon.


2 Answers

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.

like image 102
bsiamionau Avatar answered Oct 16 '22 05:10

bsiamionau


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

like image 29
Arsen Alexanyan Avatar answered Oct 16 '22 04:10

Arsen Alexanyan