|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.h2.jdbcx.JdbcConnectionPool
public class JdbcConnectionPool
A simple standalone JDBC connection pool. It is based on the MiniConnectionPoolManager written by Christian d'Heureuse (Java 1.5) . It is used as follows:
import java.sql.*; import org.h2.jdbcx.JdbcConnectionPool; public class Test { public static void main(String... args) throws Exception { JdbcConnectionPool cp = JdbcConnectionPool.create( "jdbc:h2:~/test", "sa", "sa"); for (String sql : args) { Connection conn = cp.getConnection(); conn.createStatement().execute(sql); conn.close(); } cp.dispose(); } }
Method Summary | ||
---|---|---|
static JdbcConnectionPool |
create(javax.sql.ConnectionPoolDataSource dataSource)
Constructs a new connection pool. |
|
static JdbcConnectionPool |
create(java.lang.String url,
java.lang.String user,
java.lang.String password)
Constructs a new connection pool for H2 databases. |
|
void |
dispose()
Closes all unused pooled connections. |
|
int |
getActiveConnections()
Returns the number of active (open) connections of this pool. |
|
java.sql.Connection |
getConnection()
Retrieves a connection from the connection pool. |
|
java.sql.Connection |
getConnection(java.lang.String username,
java.lang.String password)
INTERNAL |
|
int |
getLoginTimeout()
Gets the maximum time in seconds to wait for a free connection. |
|
java.io.PrintWriter |
getLogWriter()
INTERNAL |
|
int |
getMaxConnections()
Gets the maximum number of connections to use. |
|
boolean |
isWrapperFor(java.lang.Class<?> iface)
[Not supported] Checks if unwrap can return an object of this class. |
|
void |
setLoginTimeout(int seconds)
Sets the maximum time in seconds to wait for a free connection. |
|
void |
setLogWriter(java.io.PrintWriter logWriter)
INTERNAL |
|
void |
setMaxConnections(int max)
Sets the maximum number of connections to use from now on. |
|
|
unwrap(java.lang.Class<T> iface)
[Not supported] Return an object of this class if possible. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static JdbcConnectionPool create(javax.sql.ConnectionPoolDataSource dataSource)
dataSource
- the data source to create connections
public static JdbcConnectionPool create(java.lang.String url, java.lang.String user, java.lang.String password)
url
- the database URL of the H2 connectionuser
- the user namepassword
- the password
public void setMaxConnections(int max)
max
- the maximum number of connectionspublic int getMaxConnections()
public int getLoginTimeout()
getLoginTimeout
in interface javax.sql.CommonDataSource
public void setLoginTimeout(int seconds)
setLoginTimeout
in interface javax.sql.CommonDataSource
seconds
- the timeout, 0 meaning the defaultpublic void dispose() throws java.sql.SQLException
java.sql.SQLException
public java.sql.Connection getConnection() throws java.sql.SQLException
maxConnections
connections are already in use, the method
waits until a connection becomes available or timeout
seconds elapsed. When the application is finished using the connection,
it must close it in order to return it to the pool.
If no connection becomes available within the given timeout, an exception
with SQL state 08001 and vendor code 8001 is thrown.
getConnection
in interface javax.sql.DataSource
java.sql.SQLException
- when a new connection could not be established,
or a timeout occurredpublic int getActiveConnections()
Connection
objects that have been issued by
getConnection() for which Connection.close()
has
not yet been called.
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
getConnection
in interface javax.sql.DataSource
public java.io.PrintWriter getLogWriter()
getLogWriter
in interface javax.sql.CommonDataSource
public void setLogWriter(java.io.PrintWriter logWriter)
setLogWriter
in interface javax.sql.CommonDataSource
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
unwrap
in interface java.sql.Wrapper
iface
- the class
java.sql.SQLException
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
isWrapperFor
in interface java.sql.Wrapper
iface
- the class
java.sql.SQLException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |