# DataSource

public interface **DataSource** implements [CommonDataSource](https://developers.google.com/j2objc/javadoc/jre/reference/javax/sql/CommonDataSource.html) [Wrapper](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Wrapper.html) <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.

### Public Method Summary

|---|---|
| abstract [Connection](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Connection.html) | [getConnection](https://developers.google.com/j2objc/javadoc/jre/reference/javax/sql/DataSource.html#getConnection())() Attempts to establish a connection with the data source that this `DataSource` object represents. |
| abstract [Connection](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Connection.html) | [getConnection](https://developers.google.com/j2objc/javadoc/jre/reference/javax/sql/DataSource.html#getConnection(java.lang.String,%20java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) username, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) password) Attempts to establish a connection with the data source that this `DataSource` object represents. |

### Inherited Method Summary

From interface [javax.sql.CommonDataSource](https://developers.google.com/j2objc/javadoc/jre/reference/javax/sql/CommonDataSource.html)

|---|---|
| abstract [PrintWriter](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PrintWriter.html) | [getLogWriter](https://developers.google.com/j2objc/javadoc/jre/reference/javax/sql/CommonDataSource.html#getLogWriter())() Retrieves the log writer for this `DataSource` object. |
| abstract int | [getLoginTimeout](https://developers.google.com/j2objc/javadoc/jre/reference/javax/sql/CommonDataSource.html#getLoginTimeout())() Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. |
| abstract [Logger](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/logging/Logger.html) | [getParentLogger](https://developers.google.com/j2objc/javadoc/jre/reference/javax/sql/CommonDataSource.html#getParentLogger())() Return the parent Logger of all the Loggers used by this data source. |
| abstract void | [setLogWriter](https://developers.google.com/j2objc/javadoc/jre/reference/javax/sql/CommonDataSource.html#setLogWriter(java.io.PrintWriter))([PrintWriter](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PrintWriter.html) out) Sets the log writer for this `DataSource` object to the given `java.io.PrintWriter` object. |
| abstract void | [setLoginTimeout](https://developers.google.com/j2objc/javadoc/jre/reference/javax/sql/CommonDataSource.html#setLoginTimeout(int))(int seconds) Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. |

From interface [java.sql.Wrapper](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Wrapper.html)

|---|---|
| abstract boolean | [isWrapperFor](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Wrapper.html#isWrapperFor(java.lang.Class<?>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> 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 | [unwrap](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Wrapper.html#unwrap(java.lang.Class<T>))([Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<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

#### public abstract [Connection](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Connection.html)
**getConnection**
()

<br />

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

##### Returns

- a connection to the data source

##### Throws

| [SQLException](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/SQLException.html) | if a database access error occurs |
|---|---|

#### public abstract [Connection](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/Connection.html)
**getConnection**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) username, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) password)

<br />

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

##### Parameters

| username | the database user on whose behalf the connection is being made |
| password | the user's password |
|---|---|

##### Returns

- a connection to the data source

##### Throws

| [SQLException](https://developers.google.com/j2objc/javadoc/jre/reference/java/sql/SQLException.html) | if a database access error occurs |
|---|---|