List of usage examples for java.sql Connection isClosed
boolean isClosed() throws SQLException;
Connection
object has been closed. From source file:com.cws.esolutions.core.dao.impl.ServerDataDAOImpl.java
/** * @see com.cws.esolutions.core.dao.interfaces.IServerDataDAO#addServer(java.util.List) *///from w w w .ja v a 2 s . com public synchronized boolean addServer(final List<Object> serverData) throws SQLException { final String methodName = IServerDataDAO.CNAME + "#addServer(final List<Object> serverData) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); for (Object str : serverData) { DEBUGGER.debug("Value: {}", str); } } Connection sqlConn = null; boolean isComplete = false; CallableStatement stmt = null; try { sqlConn = dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall( "{CALL insertNewServer(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}"); stmt.setString(1, (String) serverData.get(0)); // systemGuid stmt.setString(2, (String) serverData.get(1)); // systemOs stmt.setString(3, (String) serverData.get(2)); // systemStatus stmt.setString(4, (String) serverData.get(3)); // systemRegion stmt.setString(5, (String) serverData.get(4)); // networkPartiton stmt.setString(6, (String) serverData.get(5)); // datacenter stmt.setString(7, (String) serverData.get(6)); // systemType stmt.setString(8, (String) serverData.get(7)); // domainName stmt.setString(9, (String) serverData.get(8)); // cpuType stmt.setInt(10, (Integer) serverData.get(9)); // cpuCount stmt.setString(11, (String) serverData.get(10)); // serverModel stmt.setString(12, (String) serverData.get(11)); // serialNumber stmt.setInt(13, (Integer) serverData.get(12)); // installedMemory stmt.setString(14, (String) serverData.get(13)); // operIp stmt.setString(15, (String) serverData.get(14)); // operHostname stmt.setString(16, (String) serverData.get(15)); // mgmtIp stmt.setString(17, (String) serverData.get(16)); // mgmtHostname stmt.setString(18, (String) serverData.get(17)); // backupIp stmt.setString(19, (String) serverData.get(18)); // backupHostname stmt.setString(20, (String) serverData.get(19)); // nasIp stmt.setString(21, (String) serverData.get(20)); // nasHostname stmt.setString(22, (String) serverData.get(21)); // natAddr stmt.setString(23, (String) serverData.get(22)); // systemComments stmt.setString(24, (String) serverData.get(23)); // engineer stmt.setString(25, (String) serverData.get(24)); // mgrEntry stmt.setInt(26, (Integer) serverData.get(25)); // dmgrPort stmt.setString(27, (String) serverData.get(26)); // serverRack stmt.setString(28, (String) serverData.get(27)); // rackPosition stmt.setString(29, (String) serverData.get(28)); // owningDmgr if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } isComplete = (!(stmt.execute())); if (DEBUG) { DEBUGGER.debug("isComplete: {}", isComplete); } } catch (SQLException sqx) { throw new SQLException(sqx.getMessage(), sqx); } finally { if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } return isComplete; }
From source file:com.cws.esolutions.core.dao.impl.ServerDataDAOImpl.java
/** * @see com.cws.esolutions.core.dao.interfaces.IServerDataDAO#updateServer(java.lang.String, java.util.List) *//*from w w w.j ava 2s . co m*/ public synchronized boolean updateServer(final String serverGuid, final List<Object> serverData) throws SQLException { final String methodName = IServerDataDAO.CNAME + "#updateServer(final String serverGuid, final List<Object> serverData) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", serverGuid); for (Object str : serverData) { DEBUGGER.debug("Value: {}", str); } } Connection sqlConn = null; boolean isComplete = false; CallableStatement stmt = null; try { sqlConn = dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall( "{CALL updateServerData(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}"); stmt.setString(1, serverGuid); // systemGuid stmt.setString(2, (String) serverData.get(1)); // systemOs stmt.setString(3, (String) serverData.get(2)); // systemStatus stmt.setString(4, (String) serverData.get(3)); // systemRegion stmt.setString(5, (String) serverData.get(4)); // networkPartiton stmt.setString(6, (String) serverData.get(5)); // datacenter stmt.setString(7, (String) serverData.get(6)); // systemType stmt.setString(8, (String) serverData.get(7)); // domainName stmt.setString(9, (String) serverData.get(8)); // cpuType stmt.setInt(10, (Integer) serverData.get(9)); // cpuCount stmt.setString(11, (String) serverData.get(10)); // serverModel stmt.setString(12, (String) serverData.get(11)); // serialNumber stmt.setInt(13, (Integer) serverData.get(12)); // installedMemory stmt.setString(14, (String) serverData.get(13)); // operIp stmt.setString(15, (String) serverData.get(14)); // operHostname stmt.setString(16, (String) serverData.get(15)); // mgmtIp stmt.setString(17, (String) serverData.get(16)); // mgmtHostname stmt.setString(18, (String) serverData.get(17)); // backupIp stmt.setString(19, (String) serverData.get(18)); // backupHostname stmt.setString(20, (String) serverData.get(19)); // nasIp stmt.setString(21, (String) serverData.get(20)); // nasHostname stmt.setString(22, (String) serverData.get(21)); // natAddr stmt.setString(23, (String) serverData.get(22)); // systemComments stmt.setString(24, (String) serverData.get(23)); // engineer stmt.setString(25, (String) serverData.get(24)); // mgrEntry stmt.setInt(26, (Integer) serverData.get(25)); // dmgrPort stmt.setString(27, (String) serverData.get(26)); // serverRack stmt.setString(28, (String) serverData.get(27)); // rackPosition stmt.setString(29, (String) serverData.get(28)); // owningDmgr if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } isComplete = (!(stmt.execute())); if (DEBUG) { DEBUGGER.debug("isComplete: {}", isComplete); } } catch (SQLException sqx) { throw new SQLException(sqx.getMessage(), sqx); } finally { if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } return isComplete; }
From source file:org.enhydra.jdbc.pool.StandardPoolDataSource.java
/** * This method tests if a connection is closed or not *//* w w w. ja v a 2s. c o m*/ public boolean checkThisObject(Object o) { PooledConnection con; Connection ret; log.debug("StandardPoolDataSource:checkThisObject verify the current object"); try { con = (PooledConnection) o; ret = con.getConnection(); // get the connection from the pool if (ret.isClosed()) { return false; } try { ret.close(); } catch (Exception e) { log.error("StandardPoolDataSource:checkThisObject can't closed the connection: " + e); } return true; } catch (java.sql.SQLException e) { log.error( "StandardPoolDataSource:checkThisObject Error java.sql.SQLException in StandardPoolDataSource:checkThisObject"); return false; } }
From source file:org.openbravo.database.ConnectionProviderImpl.java
public void releaseRollbackConnection(Connection conn) throws SQLException { if (conn == null) return;//from ww w . j a va2s . c o m // prevent extra exception if the connection is already closed // especially needed here because rollback occurs in case of // application exceptions also. If the conn.isClosed and a rollback // is done then the real app exception is hidden. if (conn.isClosed()) { return; } conn.rollback(); closeConnection(conn); }
From source file:com.mirth.connect.donkey.test.util.TestUtils.java
public static void close(Connection connection) { try {/*from ww w . ja v a 2 s.c o m*/ if (connection != null && !connection.isClosed()) { connection.rollback(); connection.close(); } } catch (SQLException e) { e.printStackTrace(); } }
From source file:com.cws.esolutions.core.dao.impl.WebMessagingDAOImpl.java
/** * @see com.cws.esolutions.core.dao.interfaces.IWebMessagingDAO#retrieveMessage(String) *//* w w w.j a v a 2 s. c o m*/ public synchronized List<Object> retrieveMessage(final String messageId) throws SQLException { final String methodName = IWebMessagingDAO.CNAME + "#retrieveMessage(final String messageId) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug(messageId); } Connection sqlConn = null; ResultSet resultSet = null; CallableStatement stmt = null; List<Object> svcMessage = null; try { sqlConn = dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall("{CALL retrServiceMessage(?)}"); stmt.setString(1, messageId); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (stmt.execute()) { resultSet = stmt.getResultSet(); if (resultSet.next()) { resultSet.first(); svcMessage = new ArrayList<Object>(); svcMessage.add(resultSet.getString(1)); // svc_message_id svcMessage.add(resultSet.getString(2)); // svc_message_title svcMessage.add(resultSet.getString(3)); // svc_message_txt svcMessage.add(resultSet.getString(4)); // svc_message_author svcMessage.add(resultSet.getTimestamp(5)); // svc_message_submitdate svcMessage.add(resultSet.getBoolean(6)); // svc_message_active svcMessage.add(resultSet.getBoolean(7)); // svc_message_alert svcMessage.add(resultSet.getBoolean(8)); // svc_message_expires svcMessage.add(resultSet.getTimestamp(9)); // svc_message_expirydate svcMessage.add(resultSet.getTimestamp(10)); // svc_message_modifiedon svcMessage.add(resultSet.getString(11)); // svc_message_modifiedby if (DEBUG) { DEBUGGER.debug("svcMessage: {}", svcMessage); } } } } catch (SQLException sqx) { ERROR_RECORDER.error(sqx.getMessage(), sqx); throw new SQLException(sqx.getMessage(), sqx); } finally { if (resultSet != null) { resultSet.close(); } if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } return svcMessage; }
From source file:com.cws.esolutions.core.dao.impl.ServerDataDAOImpl.java
/** * @see com.cws.esolutions.core.dao.interfaces.IServerDataDAO#listServers(int) *///from w w w .j av a2 s .com public synchronized List<String[]> listServers(final int startRow) throws SQLException { final String methodName = IServerDataDAO.CNAME + "#listServers(final int startRow) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", startRow); } Connection sqlConn = null; ResultSet resultSet = null; CallableStatement stmt = null; List<String[]> responseData = null; try { sqlConn = dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall("{CALL retrServerList(?)}"); stmt.setInt(1, startRow); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (stmt.execute()) { resultSet = stmt.getResultSet(); if (DEBUG) { DEBUGGER.debug("resultSet: {}", resultSet); } if (resultSet.next()) { resultSet.beforeFirst(); responseData = new ArrayList<String[]>(); while (resultSet.next()) { String[] serverData = new String[] { resultSet.getString(1), // T1.SYSTEM_GUID resultSet.getString(2), // T1.SYSTEM_REGION resultSet.getString(3), // T1.NETWORK_PARTITION resultSet.getString(4), // T1.OPER_HOSTNAME resultSet.getString(5), // T1.OWNING_DMGR resultSet.getString(6), // T2.GUID resultSet.getString(7) // T2.NAME }; if (DEBUG) { for (Object obj : serverData) { DEBUGGER.debug("Value: {}", obj); } } responseData.add(serverData); } if (DEBUG) { for (Object[] objArr : responseData) { for (Object obj : objArr) { DEBUGGER.debug("Value: {}", obj); } } } } } } catch (SQLException sqx) { throw new SQLException(sqx.getMessage(), sqx); } finally { if (resultSet != null) { resultSet.close(); } if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } return responseData; }
From source file:com.cws.esolutions.core.dao.impl.WebMessagingDAOImpl.java
/** * @see com.cws.esolutions.core.dao.interfaces.IWebMessagingDAO#retrieveMessages() *//*from ww w . j a v a 2 s.c o m*/ public synchronized List<Object[]> retrieveMessages() throws SQLException { final String methodName = IWebMessagingDAO.CNAME + "#retrieveMessages() throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); } Connection sqlConn = null; ResultSet resultSet = null; CallableStatement stmt = null; List<Object[]> response = null; try { sqlConn = dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall("{CALL retrServiceMessages()}"); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (stmt.execute()) { resultSet = stmt.getResultSet(); if (DEBUG) { DEBUGGER.debug("ResultSet: {}", resultSet); } if (resultSet.next()) { resultSet.beforeFirst(); response = new ArrayList<Object[]>(); while (resultSet.next()) { Object[] data = new Object[] { resultSet.getString(1), // svc_message_id resultSet.getString(2), // svc_message_title resultSet.getString(3), // svc_message_txt resultSet.getString(4), // svc_message_author resultSet.getTimestamp(5), // svc_message_submitdate resultSet.getBoolean(6), // svc_message_active resultSet.getBoolean(7), // svc_message_alert resultSet.getBoolean(8), // svc_message_expires resultSet.getTimestamp(9), // svc_message_expirydate resultSet.getTimestamp(10), // svc_message_modifiedon resultSet.getString(11) // svc_message_modifiedby }; if (DEBUG) { DEBUGGER.debug("data: {}", data); } response.add(data); } } } } catch (SQLException sqx) { ERROR_RECORDER.error(sqx.getMessage(), sqx); throw new SQLException(sqx.getMessage(), sqx); } finally { if (resultSet != null) { resultSet.close(); } if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } return response; }
From source file:com.cws.esolutions.core.dao.impl.WebMessagingDAOImpl.java
/** * @see com.cws.esolutions.core.dao.interfaces.IWebMessagingDAO#retrieveAlertMessages() *///from w w w.j a va 2s . c om public synchronized List<Object[]> retrieveAlertMessages() throws SQLException { final String methodName = IWebMessagingDAO.CNAME + "#retrieveAlertMessages() throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); } Connection sqlConn = null; ResultSet resultSet = null; CallableStatement stmt = null; List<Object[]> response = null; try { sqlConn = dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall("{CALL retrAlertMessages()}"); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (stmt.execute()) { resultSet = stmt.getResultSet(); if (DEBUG) { DEBUGGER.debug("ResultSet: {}", resultSet); } if (resultSet.next()) { resultSet.beforeFirst(); response = new ArrayList<Object[]>(); while (resultSet.next()) { Object[] data = new Object[] { resultSet.getString(1), // svc_message_id resultSet.getString(2), // svc_message_title resultSet.getString(3), // svc_message_txt resultSet.getString(4), // svc_message_author resultSet.getTimestamp(5), // svc_message_submitdate resultSet.getBoolean(6), // svc_message_active resultSet.getBoolean(7), // svc_message_alert resultSet.getBoolean(8), // svc_message_expires resultSet.getTimestamp(9), // svc_message_expirydate resultSet.getTimestamp(10), // svc_message_modifiedon resultSet.getString(11) // svc_message_modifiedby }; if (DEBUG) { DEBUGGER.debug("data: {}", data); } response.add(data); } } } } catch (SQLException sqx) { ERROR_RECORDER.error(sqx.getMessage(), sqx); throw new SQLException(sqx.getMessage(), sqx); } finally { if (resultSet != null) { resultSet.close(); } if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } return response; }
From source file:com.sqewd.open.dal.core.persistence.db.AbstractDbPersister.java
protected void releaseConnection(final Connection conn) { try {//from w ww . j a va 2s. c o m if (conn != null && !conn.isClosed()) { conn.close(); } } catch (Exception e) { LogUtils.stacktrace(log, e); log.error(e.getLocalizedMessage()); } }