Package javax.sql
Interface DataSource
-
- All Superinterfaces:
CommonDataSource,Wrapper
public interface DataSource extends CommonDataSource, Wrapper
An interface for the creation ofConnectionobjects which represent a connection to a database. This interface is an alternative to thejava.sql.DriverManager.A class which implements the
DataSourceinterface is typically registered with a JNDI naming service directory and is retrieved from there by name.The
DataSourceinterface is typically implemented by the writer of a JDBC driver. There are three variants of theDataSourceinterface, 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
DataSourceinterface is loaded via a JNDI lookup process. A driver loaded in this way does not register itself with theDriverManager.
-
-
Method Summary
All Methods Instance Methods Abstract Methods 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, setLogWriter
-
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
-
-
-
-
Method Detail
-
getConnection
Connection getConnection() throws SQLException
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
Connection getConnection(String theUsername, String thePassword) throws SQLException
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.
-
-