Top Description Fields Constructors Methods
org.springframework.jdbc.datasource

public abstract Class AbstractDriverBasedDataSource

extends AbstractDataSource
Class Inheritance
Known Direct Subclasses
org.springframework.jdbc.datasource.DriverManagerDataSource, org.springframework.jdbc.datasource.SimpleDriverDataSource
Imports
java.sql.Connection, .SQLException, java.util.Properties, org.springframework.lang.Nullable

Abstract base class for JDBC javax.sql.DataSource implementations that operate on a JDBC java.sql.Driver.
Author
Juergen Hoeller
Since
2.5.5
See Also
SimpleDriverDataSource, DriverManagerDataSource

Field Summary

Modifier and TypeField and Description
private String
private Properties
private String
private String
private String
private String
Inherited from org.springframework.jdbc.datasource.AbstractDataSource:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
getCatalog()

Return the database catalog to be applied to each Connection, if any.

public Connection
getConnection()

Implements javax.sql.DataSource.getConnection.

This implementation delegates to getConnectionFromDriver, using the default username and password of this DataSource.

public Connection
getConnection(String
the database user on whose behalf the connection is being made
username
,
String
the user's password
password
)

Implements javax.sql.DataSource.getConnection.

This implementation delegates to getConnectionFromDriver, using the given username and password.

protected Connection

Returns:

the obtained Connection
getConnectionFromDriver
(String
the name of the user
username
,
String
the password to use
password
)

Build properties for the Driver, including the given username and password (if any), and obtain a corresponding Connection.

protected abstract Connection

Returns:

the obtained Connection
getConnectionFromDriver
(Properties
the merged connection properties
props
)

Obtain a Connection using the given properties.

public Properties
getConnectionProperties()

Return the connection properties to be passed to the Driver, if any.

public String
getPassword()

Return the JDBC password to use for connecting through the Driver.

public String
getSchema()

Return the database schema to be applied to each Connection, if any.

public String
getUrl()

Return the JDBC URL to use for connecting through the Driver.

public String
getUsername()

Return the JDBC username to use for connecting through the Driver.

public void
setCatalog(String catalog)

Specify a database catalog to be applied to each Connection.

public void
setConnectionProperties(Properties connectionProperties)

Specify arbitrary connection properties as key/value pairs, to be passed to the Driver.

public void
setPassword(String password)

Set the JDBC password to use for connecting through the Driver.

public void
setSchema(String schema)

Specify a database schema to be applied to each Connection.

public void
setUrl(String url)

Set the JDBC URL to use for connecting through the Driver.

public void
setUsername(String username)

Set the JDBC username to use for connecting through the Driver.

Inherited from org.springframework.jdbc.datasource.AbstractDataSource:
getLoginTimeoutgetLogWritergetParentLoggerisWrapperForsetLoginTimeoutsetLogWriterunwrap

Field Detail

catalogback to summary
private String catalog
Annotations
@Nullable
connectionPropertiesback to summary
private Properties connectionProperties
Annotations
@Nullable
passwordback to summary
private String password
Annotations
@Nullable
schemaback to summary
private String schema
Annotations
@Nullable
urlback to summary
private String url
Annotations
@Nullable
usernameback to summary
private String username
Annotations
@Nullable

Constructor Detail

AbstractDriverBasedDataSourceback to summary
public AbstractDriverBasedDataSource()

Method Detail

getCatalogback to summary
public String getCatalog()

Return the database catalog to be applied to each Connection, if any.

Annotations
@Nullable
Since
4.3.2
getConnectionback to summary
public Connection getConnection() throws SQLException

Implements javax.sql.DataSource.getConnection.

This implementation delegates to getConnectionFromDriver, using the default username and password of this DataSource.

Returns:Connection

Doc from javax.sql.DataSource.getConnection.

a connection to the data source

Annotations
@Override
Exceptions
SQLException:

Doc from javax.sql.DataSource.getConnection.

if a database access error occurs

See Also
getConnectionFromDriver(String, String), setUsername, setPassword
getConnectionback to summary
public Connection getConnection(String username, String password) throws SQLException

Implements javax.sql.DataSource.getConnection.

This implementation delegates to getConnectionFromDriver, using the given username and password.

Parameters
username:String

Doc from javax.sql.DataSource.getConnection.

the database user on whose behalf the connection is being made

password:String

Doc from javax.sql.DataSource.getConnection.

the user's password

Returns:Connection

Doc from javax.sql.DataSource.getConnection.

a connection to the data source

Annotations
@Override
Exceptions
SQLException:

Doc from javax.sql.DataSource.getConnection.

if a database access error occurs

See Also
getConnectionFromDriver(String, String)
getConnectionFromDriverback to summary
protected Connection getConnectionFromDriver(String username, String password) throws SQLException

Build properties for the Driver, including the given username and password (if any), and obtain a corresponding Connection.

Parameters
username:String

the name of the user

password:String

the password to use

Returns:Connection

the obtained Connection

Exceptions
SQLException:
in case of failure
See Also
java.sql.Driver#connect(String, java.util.Properties)
getConnectionFromDriverback to summary
protected abstract Connection getConnectionFromDriver(Properties props) throws SQLException

Obtain a Connection using the given properties.

Template method to be implemented by subclasses.

Parameters
props:Properties

the merged connection properties

Returns:Connection

the obtained Connection

Exceptions
SQLException:
in case of failure
getConnectionPropertiesback to summary
public Properties getConnectionProperties()

Return the connection properties to be passed to the Driver, if any.

Annotations
@Nullable
getPasswordback to summary
public String getPassword()

Return the JDBC password to use for connecting through the Driver.

Annotations
@Nullable
getSchemaback to summary
public String getSchema()

Return the database schema to be applied to each Connection, if any.

Annotations
@Nullable
Since
4.3.2
getUrlback to summary
public String getUrl()

Return the JDBC URL to use for connecting through the Driver.

Annotations
@Nullable
getUsernameback to summary
public String getUsername()

Return the JDBC username to use for connecting through the Driver.

Annotations
@Nullable
setCatalogback to summary
public void setCatalog(String catalog)

Specify a database catalog to be applied to each Connection.

Since
4.3.2
See Also
Connection#setCatalog
setConnectionPropertiesback to summary
public void setConnectionProperties(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
java.sql.Driver#connect(String, java.util.Properties)
setPasswordback to summary
public void setPassword(String password)

Set the JDBC password to use for connecting through the Driver.

See Also
java.sql.Driver#connect(String, java.util.Properties)
setSchemaback to summary
public void setSchema(String schema)

Specify a database schema to be applied to each Connection.

Since
4.3.2
See Also
Connection#setSchema
setUrlback to summary
public void setUrl(String url)

Set the JDBC URL to use for connecting through the Driver.

See Also
java.sql.Driver#connect(String, java.util.Properties)
setUsernameback to summary
public void setUsername(String username)

Set the JDBC username to use for connecting through the Driver.

See Also
java.sql.Driver#connect(String, java.util.Properties)