Skip to content

Most visited

Recently visited

navigation
Added in API level 1

DataSource

public interface DataSource
implements CommonDataSource, Wrapper

javax.sql.DataSource


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:

  1. Standard DataSource: produces standard Connection objects with no special features.
  2. Connection Pool DataSource: produces PooledConnection objects which require a connection pool manager as an intermediary component.
  3. Distributed transaction DataSource ("XADataSource"): produces XAConnection objects which can be used to handle distributed transactions which typically require an intermediary transaction manager component. XAConnection objects 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.

Summary

Public methods

abstract Connection getConnection()

Creates a connection to the database represented by this DataSource.

abstract Connection getConnection(String theUsername, String thePassword)

Creates a connection to the database represented by this DataSource, using the supplied user name and password.

Inherited methods

From interface javax.sql.CommonDataSource
From interface java.sql.Wrapper

Public methods

getConnection

Added in API level 1
Connection getConnection ()

Creates a connection to the database represented by this DataSource.

Returns
Connection a Connection object which is a connection to the database.
Throws
SQLException if there is a problem accessing the database.

getConnection

Added in API level 1
Connection getConnection (String theUsername, 
                String thePassword)

Creates a connection to the database represented by this DataSource, using the supplied user name and password.

Parameters
theUsername String: the a user name for the database login.
thePassword String: the password associated with the user identified by theUsername.
Returns
Connection the Connection object which is the connection to the database.
Throws
SQLException if there is a problem accessing the database.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.