I am reading about Connection
s vs DataSource
s in Java and I have some questions. Is a DataSource
really just a manager and an abstraction of a Connection
(or multiple connections)?
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.
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.
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.
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.
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 Connection
s and it has a variety of implementations which operate in different manners. Such as:
Basic implementation -- produces a standard Connection object
Connection pooling implementation -- produces a Connection object that will automatically participate in connection pooling. This implementation works with a middle-tier connection pooling manager.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With