List of usage examples for javax.sql PooledConnection close
void close() throws SQLException;
PooledConnection
object represents. From source file:ConnPool.java
public static void main(String[] args) throws Exception { OracleConnectionPoolDataSource ocpds = new OracleConnectionPoolDataSource(); ocpds.setURL("jdbc:oracle:thin:@localhost:1521:ORCL"); ocpds.setUser("user"); ocpds.setPassword("password"); PooledConnection pc_1 = ocpds.getPooledConnection(); Connection conn_1 = pc_1.getConnection(); Statement stmt = conn_1.createStatement(); ResultSet rs = stmt.executeQuery("SELECT count(*) FROM v$session WHERE username = 'SYS'"); rs.next();//from w w w . java 2 s .com String msg = "Total connections after "; System.out.println(msg + "conn_1: " + rs.getString(1)); Connection conn_2 = pc_1.getConnection(); stmt = conn_2.createStatement(); rs = stmt.executeQuery("SELECT count(*) FROM v$session WHERE username = 'SYS'"); rs.next(); System.out.println(msg + "conn_2: " + rs.getString(1)); PooledConnection pc_2 = ocpds.getPooledConnection(); rs = stmt.executeQuery("SELECT count(*) FROM v$session WHERE username = 'SYS'"); rs.next(); System.out.println(msg + "pc_2: " + rs.getString(1)); conn_1.close(); conn_2.close(); pc_1.close(); pc_2.close(); }
From source file:com.microsoft.sqlserver.jdbc.connection.PoolingTest.java
@Test public void testConnectionPoolClose() throws SQLException { SQLServerXADataSource ds = new SQLServerXADataSource(); ds.setURL(connectionString);// ww w .j a va 2 s .c o m PooledConnection pc = ds.getPooledConnection(); Connection con = pc.getConnection(); pc.close(); // assert that the first connection is closed. assertTrue(con.isClosed(), "Connection is not closed with pool close"); }
From source file:com.alibaba.wasp.jdbcx.JdbcConnectionPool.java
private void closeConnection(PooledConnection pc) { try {//from w w w . ja v a 2 s. c o m pc.close(); } catch (SQLException e) { if (logWriter != null) { e.printStackTrace(logWriter); } } }
From source file:biz.source_code.miniConnectionPoolManager.TestMiniConnectionPoolManager.java
private void closeConnectionNoEx(PooledConnection pconn) { try {//from ww w . j a v a2s.co m pconn.close(); } catch (SQLException e) { log("Error while closing database connection: " + e.toString()); } }
From source file:biz.source_code.miniConnectionPoolManager.TestMiniConnectionPoolManager.java
/** * Closes all unused pooled connections. *///from w ww .j a va 2 s. c o m public synchronized void dispose() throws SQLException { if (isDisposed) return; isDisposed = true; SQLException e = null; while (!recycledConnections.isEmpty()) { PooledConnection pconn = recycledConnections.pop(); try { pconn.close(); } catch (SQLException e2) { if (e == null) e = e2; } } if (e != null) throw e; }
From source file:com.microsoft.sqlserver.jdbc.connection.PoolingTest.java
@Test public void testConnectionPoolConnFunctions() throws SQLException { String tableName = RandomUtil.getIdentifier("table"); tableName = DBTable.escapeIdentifier(tableName); String sql1 = "if exists (select * from dbo.sysobjects where name = '" + tableName + "' and type = 'U')\n" + "drop table " + tableName + "\n" + "create table " + tableName + "\n" + "(\n" + "wibble_id int primary key not null,\n" + "counter int null\n" + ");"; String sql2 = "if exists (select * from dbo.sysobjects where name = '" + tableName + "' and type = 'U')\n" + "drop table " + tableName + "\n"; SQLServerXADataSource ds = new SQLServerXADataSource(); ds.setURL(connectionString);/*from w w w . j av a 2 s . c o m*/ PooledConnection pc = ds.getPooledConnection(); Connection con = pc.getConnection(); Statement statement = con.createStatement(); statement.execute(sql1); statement.execute(sql2); con.clearWarnings(); pc.close(); }
From source file:org.enhydra.jdbc.pool.StandardPoolDataSource.java
/** * object specific work to kill the object *//* w w w .j a v a 2 s .co m*/ public void expire(Object o) { log.debug("StandardPoolDataSource:expire expire a connection, remove from the pool"); if (o == null) return; try { PooledConnection pooledCon = (PooledConnection) o; pooledCon.close(); // call close() of PooledConnection pooledCon.removeConnectionEventListener(this); log.debug("StandardPoolDataSource:expire close the connection"); } catch (java.sql.SQLException e) { log.error("StandardPoolDataSource:expire Error java.sql.SQLException in StandardPoolDataSource:expire"); } }