List of usage examples for java.sql Statement isClosed
boolean isClosed() throws SQLException;
Statement
object has been closed. From source file:com.test.db.MySqlConnection.java
/** * Closes active MySQL connection/* ww w .ja va 2 s .c o m*/ * * @param statement the active connection */ public static void close(Statement statement) { if (statement == null) return; try { if (statement.isClosed()) return; statement.close(); } catch (SQLException e) { LOGGER.error(e.getMessage(), e); } }
From source file:org.apache.phoenix.hive.util.PhoenixUtil.java
public static void closeResource(Statement stmt) throws SQLException { if (stmt != null && !stmt.isClosed()) { stmt.close();//w w w . ja v a 2s . c o m } }
From source file:org.molasdin.wbase.transaction.jdbc.JdbcEngine.java
private void closeDependencies() throws Exception { for (Statement entry : statements) { if (entry.isClosed()) { entry.close();/* w w w . ja va2 s. c om*/ } } statements.clear(); }
From source file:com.reydentx.core.client.MySQLClient.java
public void close(java.sql.Statement st) { try {//from ww w. ja va2 s. com if (st != null && !st.isClosed()) { st.close(); } } catch (Exception ex) { _logger.error(ex.getMessage(), ex); } }
From source file:fr.calamus.common.db.core.DbPool.java
private Statement getStatement(String key) { try {/*from w ww . java 2 s . c o m*/ Statement st = stMap.get(key); if (st == null || st.isClosed()) { log("creating statement"); st = createStatement(key); } else { log("returning existing statement " + st.getQueryTimeout()); } return st; } catch (SQLException ex) { ex.printStackTrace(); return null; } }
From source file:fr.calamus.common.db.core.DbPool.java
public void commitTransaction(String key) { try {/* w w w . j av a 2s . c om*/ Statement st = getStatement(key); if (st == null || st.isClosed()) { st = createStatement(key); } st.execute("commit"); transactionCnxKeys.remove(key); } catch (SQLException ex) { ex.printStackTrace(); } //closeStatement(); }
From source file:com.tera.common.database.query.CQueryService.java
@Override public void closeStatement(Statement preparedStatement) { try {// w w w . j a v a 2 s . c om if (preparedStatement.isClosed()) { // noinspection ThrowableInstanceNeverThrown log.error("Attempt to close PreparedStatement that is closed already", new Exception()); return; } Connection connection = preparedStatement.getConnection(); preparedStatement.close(); connection.close(); } catch (Exception e) { log.error("Error while closing PreparedStatement", e); } }
From source file:com.micromux.cassandra.jdbc.PooledTest.java
@Test public void statementClosed() throws Exception { CassandraDataSource connectionPoolDataSource = new CassandraDataSource(HOST, PORT, KEYSPACE, USER, PASSWORD, VERSION, CONSISTENCY, TRUST_STORE, TRUST_PASS); DataSource pooledCassandraDataSource = new PooledCassandraDataSource(connectionPoolDataSource); Connection connection = pooledCassandraDataSource.getConnection(); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery("SELECT someInt FROM pooled_test WHERE somekey = 'world'"); assertTrue(resultSet.next());/*from w w w . j av a 2 s . c o m*/ assertEquals(1, resultSet.getInt(1)); assertFalse(resultSet.next()); resultSet.close(); connection.close(); assert statement.isClosed(); }
From source file:com.alibaba.druid.benckmark.pool.Oracle_Case3.java
private void p0(final DataSource dataSource, String name, int threadCount) throws Exception { final CountDownLatch startLatch = new CountDownLatch(1); final CountDownLatch endLatch = new CountDownLatch(threadCount); for (int i = 0; i < threadCount; ++i) { Thread thread = new Thread() { public void run() { try { startLatch.await();/*from w ww.j a v a2s .co m*/ for (int i = 0; i < LOOP_COUNT; ++i) { Connection conn = dataSource.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT 1 FROM DUAL"); rs.next(); // Assert.isTrue(!rs.isClosed()); rs.close(); // Assert.isTrue(!stmt.isClosed()); stmt.close(); Assert.isTrue(stmt.isClosed()); conn.close(); } } catch (Exception ex) { ex.printStackTrace(); } endLatch.countDown(); } }; thread.start(); } long startMillis = System.currentTimeMillis(); long startYGC = TestUtil.getYoungGC(); long startFullGC = TestUtil.getFullGC(); startLatch.countDown(); endLatch.await(); long millis = System.currentTimeMillis() - startMillis; long ygc = TestUtil.getYoungGC() - startYGC; long fullGC = TestUtil.getFullGC() - startFullGC; System.out.println("thread " + threadCount + " " + name + " millis : " + NumberFormat.getInstance().format(millis) + ", YGC " + ygc + " FGC " + fullGC); }
From source file:com.sqewd.open.dal.core.persistence.db.H2DbPersister.java
@Override protected Object getSequenceValue(Entity entity, StructAttributeReflect attr, Connection conn) throws Exception { if (EnumPrimitives.isPrimitiveType(attr.Field.getType())) { EnumPrimitives prim = EnumPrimitives.type(attr.Field.getType()); if (prim == EnumPrimitives.ELong || prim == EnumPrimitives.EInteger) { String seqname = SimpleDbQuery.getSequenceName(entity, attr); String sql = "select NEXT VALUE FOR " + seqname; Statement stmnt = conn.createStatement(); try { ResultSet rs = stmnt.executeQuery(sql); while (rs.next()) { return rs.getLong(1); }// ww w. j a v a2 s .co m if (rs != null) rs.close(); } finally { if (stmnt != null && !stmnt.isClosed()) stmnt.close(); } } } else if (attr.Field.getType().equals(String.class)) { UUID uuid = UUID.randomUUID(); return uuid.toString(); } throw new Exception("Cannot generate sequence for type [" + attr.Field.getType().getCanonicalName() + "]"); }