Package org.springframework.jdbc.datasource

# Class AbstractDriverBasedDataSource

java.lang.Object
org.springframework.jdbc.datasource.AbstractDataSource
org.springframework.jdbc.datasource.AbstractDriverBasedDataSource

All Implemented Interfaces:
  `Wrapper`, `CommonDataSource`, `DataSource`

Direct Known Subclasses:
  `DriverManagerDataSource`, `SimpleDriverDataSource`

public abstract class AbstractDriverBasedDataSource extends AbstractDataSource
Abstract base class for JDBC `DataSource` implementations that operate on a JDBC `Driver`.

Since:
  2.5.5
Author:
  Juergen Hoeller
See Also:
  - `SimpleDriverDataSource`
  - `DriverManagerDataSource`

## Field Summary

### Fields inherited from class org.springframework.jdbc.datasource.AbstractDataSource

`logger`

## Constructor Summary

Constructors
Constructor
Description
`AbstractDriverBasedDataSource()`

## Method Summary

Modifier and Type
Method
Description
`String`
`getCatalog()`
Return the database catalog to be applied to each Connection, if any.
`Connection`
`getConnection()`
This implementation delegates to `getConnectionFromDriver`, using the default username and password of this DataSource.
`Connection`
`getConnection(String username, String password)`
This implementation delegates to `getConnectionFromDriver`, using the given username and password.
`protected Connection`
`getConnectionFromDriver(String username, String password)`
Build properties for the Driver, including the given username and password (if any), and obtain a corresponding Connection.
`protected abstract Connection`
`getConnectionFromDriver(Properties props)`
Obtain a Connection using the given properties.
`Properties`
`getConnectionProperties()`
Return the connection properties to be passed to the Driver, if any.
`String`
`getPassword()`
Return the JDBC password to use for connecting through the Driver.
`String`
`getSchema()`
Return the database schema to be applied to each Connection, if any.
`String`
`getUrl()`
Return the JDBC URL to use for connecting through the Driver.
`String`
`getUsername()`
Return the JDBC username to use for connecting through the Driver.
`void`
`setCatalog(String catalog)`
Specify a database catalog to be applied to each Connection.
`void`
`setConnectionProperties(Properties connectionProperties)`
Specify arbitrary connection properties as key/value pairs, to be passed to the Driver.
`void`
`setPassword(String password)`
Set the JDBC password to use for connecting through the Driver.
`void`
`setSchema(String schema)`
Specify a database schema to be applied to each Connection.
`void`
`setUrl(String url)`
Set the JDBC URL to use for connecting through the Driver.
`void`
`setUsername(String username)`
Set the JDBC username to use for connecting through the Driver.

### Methods inherited from class org.springframework.jdbc.datasource.AbstractDataSource

`getLoginTimeout, getLogWriter, getParentLogger, isWrapperFor, setLoginTimeout, setLogWriter, unwrap`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface javax.sql.CommonDataSource

`createShardingKeyBuilder`

### Methods inherited from interface javax.sql.DataSource

`createConnectionBuilder`

## Constructor Details

### AbstractDriverBasedDataSource

public AbstractDriverBasedDataSource()

## Method Details

### setUrl

public void setUrl(@Nullable String url)
Set the JDBC URL to use for connecting through the Driver.

See Also:
  - `Driver.connect(String, java.util.Properties)`

### getUrl

@Nullable public String getUrl()
Return the JDBC URL to use for connecting through the Driver.

### setUsername

public void setUsername(@Nullable String username)
Set the JDBC username to use for connecting through the Driver.

See Also:
  - `Driver.connect(String, java.util.Properties)`

### getUsername

@Nullable public String getUsername()
Return the JDBC username to use for connecting through the Driver.

### setPassword

public void setPassword(@Nullable String password)
Set the JDBC password to use for connecting through the Driver.

See Also:
  - `Driver.connect(String, java.util.Properties)`

### getPassword

@Nullable public String getPassword()
Return the JDBC password to use for connecting through the Driver.

### setCatalog

public void setCatalog(@Nullable String catalog)
Specify a database catalog to be applied to each Connection.

Since:
  4.3.2
See Also:
  - `Connection.setCatalog(java.lang.String)`

### getCatalog

@Nullable public String getCatalog()
Return the database catalog to be applied to each Connection, if any.

Since:
  4.3.2

### setSchema

public void setSchema(@Nullable String schema)
Specify a database schema to be applied to each Connection.

Since:
  4.3.2
See Also:
  - `Connection.setSchema(java.lang.String)`

### getSchema

@Nullable public String getSchema()
Return the database schema to be applied to each Connection, if any.

Since:
  4.3.2

### setConnectionProperties

public void setConnectionProperties(@Nullable Properties connectionProperties)
Specify arbitrary connection properties as key/value pairs, to be passed to the Driver.

Can also contain "user" and "password" properties. However, any "username" and "password" bean properties specified on this DataSource will override the corresponding connection properties.

See Also:
  - `Driver.connect(String, java.util.Properties)`

### getConnectionProperties

@Nullable public Properties getConnectionProperties()
Return the connection properties to be passed to the Driver, if any.

### getConnection

public Connection getConnection() throws SQLException
This implementation delegates to `getConnectionFromDriver`, using the default username and password of this DataSource.

Throws:
  `SQLException`
See Also:
  - `getConnectionFromDriver(String, String)`
  - `setUsername(java.lang.String)`
  - `setPassword(java.lang.String)`

### getConnection

public Connection getConnection(String username, String password) throws SQLException
This implementation delegates to `getConnectionFromDriver`, using the given username and password.

Throws:
  `SQLException`
See Also:
  - `getConnectionFromDriver(String, String)`

### getConnectionFromDriver

protected Connection getConnectionFromDriver(@Nullable String username, @Nullable String password) throws SQLException
Build properties for the Driver, including the given username and password (if any), and obtain a corresponding Connection.

Parameters:
  `username` - the name of the user
  `password` - the password to use
Returns:
  the obtained Connection
Throws:
  `SQLException` - in case of failure
See Also:
  - `Driver.connect(String, java.util.Properties)`

### getConnectionFromDriver

protected abstract Connection getConnectionFromDriver(Properties props) throws SQLException
Obtain a Connection using the given properties.

Template method to be implemented by subclasses.

Parameters:
  `props` - the merged connection properties
Returns:
  the obtained Connection
Throws:
  `SQLException` - in case of failure