Package javax.sql
Interface DataSource
- All Superinterfaces:
CommonDataSource,Wrapper
public interface DataSource extends CommonDataSource, Wrapper
An interface for the creation of
Connection objects which represent a
connection to a database. This interface is an alternative to the
java.sql.DriverManager.
A class which implements the DataSource interface is typically
registered with a JNDI naming service directory and is retrieved from there
by name.
The DataSource interface is typically implemented by the writer of a
JDBC driver. There are three variants of the DataSource interface,
which produce connections with different characteristics:
- Standard
DataSource: produces standardConnectionobjects with no special features. - Connection Pool
DataSource: producesPooledConnectionobjects which require a connection pool manager as an intermediary component. - Distributed transaction
DataSource("XADataSource"): producesXAConnectionobjects which can be used to handle distributed transactions which typically require an intermediary transaction manager component.XAConnectionobjects also provide connection pooling capabilities as well as distributed transaction capabilities.
Note that a JDBC driver which is accessed via the DataSource
interface is loaded via a JNDI lookup process. A driver loaded in this way
does not register itself with the DriverManager.
-
Method Summary
Modifier and Type Method Description ConnectiongetConnection()Creates a connection to the database represented by thisDataSource.ConnectiongetConnection(String theUsername, String thePassword)Creates a connection to the database represented by thisDataSource, using the supplied user name and password.Methods inherited from interface javax.sql.CommonDataSource
getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriterMethods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
-
Method Details
-
getConnection
Creates a connection to the database represented by thisDataSource.- Returns:
- a
Connectionobject which is a connection to the database. - Throws:
SQLException- if there is a problem accessing the database.
-
getConnection
Creates a connection to the database represented by thisDataSource, using the supplied user name and password.- Parameters:
theUsername- the a user name for the database login.thePassword- the password associated with the user identified bytheUsername.- Returns:
- the
Connectionobject which is the connection to the database. - Throws:
SQLException- if there is a problem accessing the database.
-