public class SimpleDbConnectionFactory extends Object implements DbConnectionFactory
DbConnectionFactorythat creates a new connection for every request and does no caching or connection sharing.
Note that no real connection pooling is occurring within this class. This factory will be an inefficient connection management scheme for most real-world applications. It was designed only for development/debugging purposes and for applications that are very infrequently used. In those cases, caching idle database connections for long periods of time can be wasteful, and this pooling scheme would be appropriate.
This manager simply initializes the JDBC driver and then stores the database credential information (if any). Then when a connection is requested, a new connection is made with the stored credentials (if any).
|Constructor and Description|
|Modifier and Type||Method and Description|
Clear all database URL and credential information so no more connections can be requested.
Create a new connection for the given database URL.
Initialize a database factory with the given URL, driver classname, and database credentials.
Replace a database connection back in the pool of available connections for its parent pool.
public void init(String dbUrl, String dbDriver, String username, String password) throws ClassNotFoundException
init method should be called.
Initialize a new database pool with the given database username and
password. This method will load the JDBC driver and store the given
database credentials. When a connection is requested, a new connection
will be made using the credentials.
dbUrl- the JDBC URL used to retrieve connections
dbDriver- a fully qualified class name for the JDBC driver that will handle this JDBC URL
username- the name to use to authenticate us with the database
password- the credentials use to authenticate the username
ClassNotFoundException- if any.
public void destroy()
public Connection getConnection() throws SQLException
public void releaseConnection(Connection connection) throws SQLException
Copyright © 2015. All rights reserved.