List of usage examples for java.sql Connection isClosed
boolean isClosed() throws SQLException;
Connection
object has been closed. From source file:com.paladin.sys.db.DBManager.java
public static final Connection getConnection() { Connection conn = conns.get(); try {/*w ww. j a v a 2 s . c o m*/ if (conn == null || conn.isClosed()) { conn = dataSource.getConnection(); conns.set(conn); } } catch (Exception e) { e.printStackTrace(); } return (show_sql && !Proxy.isProxyClass(conn.getClass())) ? new DebugConnection(conn).getConnection() : conn; }
From source file:com.paladin.sys.db.DBManager.java
/** * /*from w w w .j av a 2s . c o m*/ */ public static final void closeConnection() { Connection conn = conns.get(); try { if (conn != null && !conn.isClosed()) { conn.setAutoCommit(true); conn.close(); } } catch (SQLException e) { log.error("Unable to close connection!!! ", e); } conns.set(null); }
From source file:CheckJDBCInstallation_MySQL.java
/** * Test Validity of JDBC Installation/*from w ww . j a va 2s . c o m*/ * * @param conn * a JDBC connection object * @return true if a given connection object is a valid one; otherwise return * false. * @throws Exception * Failed to determine if a given connection is valid. */ public static boolean isValidConnection(Connection conn) throws Exception { if (conn == null) { // null connection object is not valid return false; } if (conn.isClosed()) { // closed connection object is not valid return false; } // for MySQL database: // you may use the connection object // with query of "select 1"; if the // query returns the result, then it // is a valid connection object. return testConnection(conn, "select 1"); }
From source file:CheckJDBCInstallation_Oracle.java
/** * Test Validity of JDBC Installation//from w ww . j a va 2 s .c o m * * @param conn * a JDBC connection object * @return true if a given connection object is a valid one; otherwise return * false. * @throws Exception * Failed to determine if a given connection is valid. */ public static boolean isValidConnection(Connection conn) throws Exception { if (conn == null) { // null connection object is not valid return false; } if (conn.isClosed()) { // closed connection object is not valid return false; } // for Oracle database: // you may use the connection object // with query of "select 1 from dual"; // if the query returns the result, then // it is a valid connection object. return testConnection(conn, "select 1 from dual"); }
From source file:com.test.db.MySqlConnection.java
/** * Closes active MySQL connection//from w w w .j a va 2s . c o m * * @param connection the active connection */ public static void close(Connection connection) { if (connection == null) return; try { if (connection.isClosed()) return; connection.close(); } catch (SQLException e) { LOGGER.error(e.getMessage(), e); } }
From source file:org.castor.jdo.util.JDOUtils.java
/** * Closes the Connection without throwing SQLException. A warning is added * to the log if SQLException is thrown. * /*from ww w.j a v a 2 s. c o m*/ * @param conn The Connection to close */ public static void closeConnection(final Connection conn) { if (conn != null) { try { if (!conn.isClosed()) { conn.close(); } } catch (SQLException e) { LOG.warn(Messages.message("persist.connClosingFailed"), e); } } }
From source file:org.apache.phoenix.hive.util.PhoenixUtil.java
public static void closeResource(Connection conn) throws SQLException { if (conn != null && !conn.isClosed()) { conn.close();/*from ww w. j a va2s . c om*/ } }
From source file:org.mskcc.cbio.cgds.dao.JdbcUtil.java
public static void closeConnection(String requester, Connection con) { try {// ww w .ja va 2s . c o m if (con != null && !con.isClosed()) { con.close(); if (requester != null) { activeConnectionCount.put(requester, activeConnectionCount.get(requester) - 1); } if (ds.getNumActive() >= MAX_JDBC_CONNECTIONS / 2) { System.err.println("Closed a MySQL connection. Active connections: " + ds.getNumActive() + "\n" + activeConnectionCount.toString()); } } } catch (SQLException e) { e.printStackTrace(); } }
From source file:com.skilrock.lms.common.db.DBConnect.java
public static void closeCon(Connection con) { try {// w ww. j a va 2 s. c om if (con == null || con.isClosed()) logger.info("Connection Already Closed Or Empty"); else con.close(); } catch (SQLException ex) { logger.error("Problem While closing Connection"); ex.printStackTrace(); } }
From source file:org.mskcc.cbio.portal.dao.JdbcUtil.java
private static void closeConnection(String requester, Connection con) { try {// ww w. ja va2 s . co m if (con != null && !con.isClosed()) { con.close(); if (requester != null) { int count = activeConnectionCount.get(requester) - 1; if (count < 0) { // since adding connection is not synchronized, the count may not be the real one count = 0; } activeConnectionCount.put(requester, count); } } } catch (Exception e) { logMessage("Problem Closed a MySQL connection from " + requester + ": " + activeConnectionCount.toString()); e.printStackTrace(); } }