Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/javax/sql/DataSource#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/javax/sql/DataSource#inhmethods)

# DataSource

` public interface DataSource `   
` implements https://developer.android.com/reference/javax/sql/CommonDataSource, https://developer.android.com/reference/java/sql/Wrapper `

|---|
| javax.sql.DataSource |

<br />

*** ** * ** ***

<br />

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. An object that implements the `DataSource` interface will typically be registered with a naming service based on the Java^TM^ Naming and Directory (JNDI) API.

The `DataSource` interface is implemented by a driver vendor. There are three types of implementations:

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.

A `DataSource` object has properties that can be modified when necessary. For example, if the data source is moved to a different server, the property for the server can be changed. The benefit is that because the data source's properties can be changed, any code accessing that data source does not need to be changed.

A driver that is accessed via a `DataSource` object does not register itself with the `DriverManager`. Rather, a `DataSource` object is retrieved though a lookup operation and then used to create a `Connection` object. With a basic implementation, the connection obtained through a `DataSource` object is identical to a connection obtained through the `DriverManager` facility.

## Summary

| ### Public methods ||
|---|---|
| ` abstract https://developer.android.com/reference/java/sql/Connection` | ` https://developer.android.com/reference/javax/sql/DataSource#getConnection()() ` <br /> Attempts to establish a connection with the data source that this `DataSource` object represents. |
| ` abstract https://developer.android.com/reference/java/sql/Connection` | ` https://developer.android.com/reference/javax/sql/DataSource#getConnection(java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String username, https://developer.android.com/reference/java/lang/String password) ` <br /> Attempts to establish a connection with the data source that this `DataSource` object represents. |

### Inherited methods

From interface ` https://developer.android.com/reference/javax/sql/CommonDataSource ` ` abstract https://developer.android.com/reference/java/io/PrintWriter` ` https://developer.android.com/reference/javax/sql/CommonDataSource#getLogWriter()() `

<br />

Retrieves the log writer for this `DataSource` object.
` abstract int` ` https://developer.android.com/reference/javax/sql/CommonDataSource#getLoginTimeout()() `

Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.
` abstract https://developer.android.com/reference/java/util/logging/Logger` ` https://developer.android.com/reference/javax/sql/CommonDataSource#getParentLogger()() `

Return the parent Logger of all the Loggers used by this data source.
` abstract void` ` https://developer.android.com/reference/javax/sql/CommonDataSource#setLogWriter(java.io.PrintWriter)(https://developer.android.com/reference/java/io/PrintWriter out) `

<br />

Sets the log writer for this `DataSource` object to the given `java.io.PrintWriter` object.
` abstract void` ` https://developer.android.com/reference/javax/sql/CommonDataSource#setLoginTimeout(int)(int seconds) `

<br />

Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
From interface ` https://developer.android.com/reference/java/sql/Wrapper ` ` abstract boolean` ` https://developer.android.com/reference/java/sql/Wrapper#isWrapperFor(java.lang.Class<?>)(https://developer.android.com/reference/java/lang/Class<?> iface) `

Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does.
` abstract <T> T` ` https://developer.android.com/reference/java/sql/Wrapper#unwrap(java.lang.Class<T>)(https://developer.android.com/reference/java/lang/Class<T> iface) `

Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.

## Public methods

### getConnection

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract Connection getConnection ()
```

<br />

Attempts to establish a connection with the data source that this `DataSource` object represents.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/sql/Connection` | a connection to the data source <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/sql/SQLException` | if a database access error occurs |

### getConnection

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract Connection getConnection (String username, 
                String password)
```

<br />

Attempts to establish a connection with the data source that this `DataSource` object represents.

<br />

| Parameters ||
|---|---|
| `username` | `String`: the database user on whose behalf the connection is being made <br /> |
| `password` | `String`: the user's password <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/sql/Connection` | a connection to the data source <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/sql/SQLException` | if a database access error occurs |