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();
}
}
| Modifier and Type | Field and Description |
|---|---|
| private AtomicInteger | |
| private final ConnectionPoolDataSource | |
| private static final int | |
| private static final int | |
| private AtomicBoolean | |
| private PrintWriter | |
| private volatile int | |
| private final Queue | |
| private volatile int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | connectionClosed(ConnectionEvent
an event object describing the source of
the event event)Implements javax. INTERNAL |
| public void | connectionErrorOccurred(ConnectionEvent
an event object describing the source of
the event and containing the event)SQLException that the
driver is about to throwImplements javax. INTERNAL |
| public static JdbcConnectionPool | Returns: the connection poolthe data source to create connections dataSource)Constructs a new connection pool. |
| public static JdbcConnectionPool | |
| public void | |
| public int | Returns: the number of active connections.Returns the number of active (open) connections of this pool. |
| public Connection | Returns: a new Connection object.Implements javax. Retrieves a connection from the connection pool. |
| public Connection | getConnection(String
the database user on whose behalf the connection is
being made user, String the user's password password)Implements javax. INTERNAL |
| private Connection | |
| public int | Returns: the timeout in secondsImplements javax. Gets the maximum time in seconds to wait for a free connection. |
| public PrintWriter | |
| public int | Returns: the max the maximum number of connectionsGets the maximum number of connections to use. |
| public java. | |
| public boolean | Returns: whether or not the interface is assignable from this classthe class iface)Implements java. Checks if unwrap can return an object of this class. |
| private void | recycleConnection(PooledConnection
the pooled connection pc)This method usually puts the connection back into the pool. |
| public void | setLoginTimeout(int
the timeout, 0 meaning the default seconds)Implements javax. Sets the maximum time in seconds to wait for a free connection. |
| public void | setLogWriter(PrintWriter
the new log writer; to disable logging, set to null logWriter)Implements javax. INTERNAL |
| public void | setMaxConnections(int
the maximum number of connections max)Sets the maximum number of connections to use from now on. |
| public <T> T | Returns: thisthe class iface)Implements java. Return an object of this class if possible. |
| activeConnections | back to summary |
|---|---|
| private AtomicInteger activeConnections | |
| dataSource | back to summary |
|---|---|
| private final ConnectionPoolDataSource dataSource | |
| DEFAULT_MAX_CONNECTIONS | back to summary |
|---|---|
| private static final int DEFAULT_MAX_CONNECTIONS | |
| DEFAULT_TIMEOUT | back to summary |
|---|---|
| private static final int DEFAULT_TIMEOUT | |
| isDisposed | back to summary |
|---|---|
| private AtomicBoolean isDisposed | |
| logWriter | back to summary |
|---|---|
| private PrintWriter logWriter | |
| maxConnections | back to summary |
|---|---|
| private volatile int maxConnections | |
| recycledConnections | back to summary |
|---|---|
| private final Queue<PooledConnection> recycledConnections | |
| timeout | back to summary |
|---|---|
| private volatile int timeout | |
| JdbcConnectionPool | back to summary |
|---|---|
| private JdbcConnectionPool(ConnectionPoolDataSource dataSource) | |
| closeConnection | back to summary |
|---|---|
| private void closeConnection(PooledConnection pc) | |
| connectionClosed | back to summary |
|---|---|
| public void connectionClosed(ConnectionEvent event) Implements javax. INTERNAL
| |
| connectionErrorOccurred | back to summary |
|---|---|
| public void connectionErrorOccurred(ConnectionEvent event) Implements javax. INTERNAL
| |
| create | back to summary |
|---|---|
| public static JdbcConnectionPool create(ConnectionPoolDataSource dataSource) Constructs a new connection pool.
| |
| create | back to summary |
|---|---|
| public static JdbcConnectionPool create(String url, String user, String password) Constructs a new connection pool for H2 databases.
| |
| dispose | back to summary |
|---|---|
| public void dispose() Closes all unused pooled connections. Exceptions while closing are written to the log stream (if set). | |
| getActiveConnections | back to summary |
|---|---|
| public int getActiveConnections() Returns the number of active (open) connections of this pool. This is the
number of
| |
| getConnection | back to summary |
|---|---|
| public Connection getConnection() throws SQLException Implements javax. Retrieves a connection from the connection pool. If
| |
| getConnection | back to summary |
|---|---|
| public Connection getConnection(String user, String password) Implements javax. INTERNAL
| |
| getConnectionNow | back to summary |
|---|---|
| private Connection getConnectionNow() throws SQLException | |
| getLoginTimeout | back to summary |
|---|---|
| public int getLoginTimeout() Implements javax. Gets the maximum time in seconds to wait for a free connection.
| |
| getLogWriter | back to summary |
|---|---|
| public PrintWriter getLogWriter() Implements javax. INTERNAL
| |
| getMaxConnections | back to summary |
|---|---|
| public int getMaxConnections() Gets the maximum number of connections to use.
| |
| getParentLogger | back to summary |
|---|---|
| public java. Implements javax. [Not supported]
| |
| isWrapperFor | back to summary |
|---|---|
| public boolean isWrapperFor(Class<?> iface) throws SQLException Implements java. Checks if unwrap can return an object of this class.
| |
| recycleConnection | back to summary |
|---|---|
| private void recycleConnection(PooledConnection pc) This method usually puts the connection back into the pool. There are some exceptions: if the pool is disposed, the connection is disposed as well. If the pool is full, the connection is closed.
| |
| setLoginTimeout | back to summary |
|---|---|
| public void setLoginTimeout(int seconds) Implements javax. Sets the maximum time in seconds to wait for a free connection. The default timeout is 30 seconds. Calling this method with the value 0 will set the timeout to the default value.
| |
| setLogWriter | back to summary |
|---|---|
| public void setLogWriter(PrintWriter logWriter) Implements javax. INTERNAL
| |
| setMaxConnections | back to summary |
|---|---|
| public void setMaxConnections(int max) Sets the maximum number of connections to use from now on. The default value is 10 connections.
| |
| unwrap | back to summary |
|---|---|
| public <T> T unwrap(Class<T> iface) throws SQLException Implements java. Return an object of this class if possible.
| |