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
Abstract base class for JDBC
DataSource implementations
that operate on a JDBC Driver.- Since:
- 2.5.5
- Author:
- Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from class AbstractDataSource
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturn the database catalog to be applied to each Connection, if any.This implementation delegates togetConnectionFromDriver, using the default username and password of this DataSource.getConnection(String username, String password) This implementation delegates togetConnectionFromDriver, using the given username and password.protected ConnectiongetConnectionFromDriver(@Nullable String username, @Nullable String password) Build properties for the Driver, including the given username and password (if any), and obtain a corresponding Connection.protected abstract ConnectionObtain a Connection using the given properties.Return the connection properties to be passed to the Driver, if any.Return the JDBC password to use for connecting through the Driver.Return the database schema to be applied to each Connection, if any.getUrl()Return the JDBC URL to use for connecting through the Driver.Return the JDBC username to use for connecting through the Driver.voidsetCatalog(@Nullable String catalog) Specify a database catalog to be applied to each Connection.voidsetConnectionProperties(@Nullable Properties connectionProperties) Specify arbitrary connection properties as key/value pairs, to be passed to the Driver.voidsetPassword(@Nullable String password) Set the JDBC password to use for connecting through the Driver.voidSpecify a database schema to be applied to each Connection.voidSet the JDBC URL to use for connecting through the Driver.voidsetUsername(@Nullable String username) Set the JDBC username to use for connecting through the Driver.Methods inherited from class AbstractDataSource
getLoginTimeout, getLogWriter, getParentLogger, isWrapperFor, setLoginTimeout, setLogWriter, unwrapMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CommonDataSource
createShardingKeyBuilderMethods inherited from interface DataSource
createConnectionBuilder
-
Constructor Details
-
AbstractDriverBasedDataSource
public AbstractDriverBasedDataSource()
-
-
Method Details
-
setUrl
-
getUrl
-
setUsername
-
getUsername
-
setPassword
-
getPassword
-
setCatalog
-
getCatalog
-
setSchema
-
getSchema
-
setConnectionProperties
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:
-
getConnectionProperties
Return the connection properties to be passed to the Driver, if any. -
getConnection
This implementation delegates togetConnectionFromDriver, using the default username and password of this DataSource.- Throws:
SQLException- See Also:
-
getConnection
This implementation delegates togetConnectionFromDriver, using the given username and password.- Throws:
SQLException- See Also:
-
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 userpassword- the password to use- Returns:
- the obtained Connection
- Throws:
SQLException- in case of failure- See Also:
-
getConnectionFromDriver
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
-