public class JDBCConnectionPool
extends java.lang.Object
JDBCConnectionPool pool = new JDBCConnectionPool(jdbcURL, userName, passwd); ... Connection conn = pool.takeConnection(); // do stuff with conn pool.putConnection(conn); // don't use conn from here on Statement stmt = pool.takeStatement(); // do stuff with stmt pool.putStatement(stmt); // don't do anything else with stmt
It is not a good idea to call close()
on a connection you
get from a pool. This would prevent it from being re-used. Also, we have
seen some odd behavior with connections involved in transactions being
re-used. We have not yet identified exactly how you can safely use a
pooled connection for transaction-safe code.
Note: We should probably be moving to a propper connection pool API. Let's standardise on one soon.
Constructor and Description |
---|
JDBCConnectionPool(java.lang.String url) |
JDBCConnectionPool(java.lang.String url,
java.lang.String user,
java.lang.String pass) |
Modifier and Type | Method and Description |
---|---|
void |
putConnection(java.sql.Connection c) |
void |
putStatement(java.sql.Statement st) |
java.sql.Connection |
takeConnection() |
java.sql.Statement |
takeStatement() |
public JDBCConnectionPool(java.lang.String url, java.lang.String user, java.lang.String pass)
public JDBCConnectionPool(java.lang.String url)
public java.sql.Connection takeConnection() throws java.sql.SQLException
java.sql.SQLException
public void putConnection(java.sql.Connection c) throws java.sql.SQLException
java.sql.SQLException
public java.sql.Statement takeStatement() throws java.sql.SQLException
java.sql.SQLException
public void putStatement(java.sql.Statement st) throws java.sql.SQLException
java.sql.SQLException