List of usage examples for java.sql Connection isClosed
boolean isClosed() throws SQLException;
Connection
object has been closed. From source file:com.adaptris.core.util.JdbcUtil.java
/** * Convenience method to get the {@link Connection} either from the * {@link com.adaptris.core.AdaptrisMessage} object or from configuration. * /*from w w w .ja v a2 s . c o m*/ * @param msg the adaptrisMessage object * @param adpCon the configured {@link AdaptrisConnection} * @return the connection either from the adaptris message or from configuration. */ public static Connection getConnection(AdaptrisMessage msg, AdaptrisConnection adpCon) throws SQLException { Connection conn = (Connection) msg.getObjectHeaders() .get(JdbcConstants.OBJ_METADATA_DATABASE_CONNECTION_KEY); if (conn != null && !conn.isClosed()) { return conn; } else { return adpCon.retrieveConnection(DatabaseConnection.class).connect(); } }
From source file:org.oscarehr.util.TrackingBasicDataSource.java
public static void releaseThreadConnections() { HashSet<Connection> threadConnections = connections.get(); if (threadConnections != null && threadConnections.size() > 0) { threadConnections = new HashSet<Connection>(threadConnections); for (Connection c : threadConnections) { try { if (!c.isClosed()) { c.close();//from www . j a va2s.c om } } catch (SQLException e) { logger.error("Error closing jdbc connection.", e); } } } connections.remove(); }
From source file:ips1ap101.lib.core.db.util.DB.java
public static boolean rollback(Connection connection) { if (connection != null) { try {/* ww w .jav a 2s . co m*/ if (!connection.isClosed() && !connection.getAutoCommit()) { connection.rollback(); } return true; } catch (SQLException ex) { Bitacora.logFatal(ex); } } return false; }
From source file:ips1ap101.lib.core.db.util.DB.java
public static boolean close(Connection connection) { if (connection != null) { try {//from w w w.j a va 2 s. c om if (!connection.isClosed()) { Bitacora.stamp(connection, "*** close ***"); connection.close(); } return true; } catch (SQLException ex) { Bitacora.logFatal(ex); } } return false; }
From source file:org.wso2.mobile.utils.persistence.EMMDBInitializer.java
public static String getDatabaseType(Connection conn) throws Exception { String type = null;/*w w w. ja va 2 s . c om*/ try { if (conn != null && (!conn.isClosed())) { DatabaseMetaData metaData = conn.getMetaData(); String databaseProductName = metaData.getDatabaseProductName(); if (databaseProductName.matches("(?i).*hsql.*")) { type = "hsql"; } else if (databaseProductName.matches("(?i).*derby.*")) { type = "derby"; } else if (databaseProductName.matches("(?i).*mysql.*")) { type = "mysql"; } else if (databaseProductName.matches("(?i).*oracle.*")) { type = "oracle"; } else if (databaseProductName.matches("(?i).*microsoft.*")) { type = "mssql"; } else if (databaseProductName.matches("(?i).*h2.*")) { type = "h2"; } else if (databaseProductName.matches("(?i).*db2.*")) { type = "db2"; } else if (databaseProductName.matches("(?i).*postgresql.*")) { type = "postgresql"; } else if (databaseProductName.matches("(?i).*openedge.*")) { type = "openedge"; } else if (databaseProductName.matches("(?i).*informix.*")) { type = "informix"; } else { String msg = "Unsupported database: " + databaseProductName + ". Database will not be created automatically by the WSO2 EMM Server. " + "Please create the database using appropriate database scripts for " + "the database."; throw new Exception(msg); } } } catch (SQLException e) { String msg = "Failed to create emm database." + e.getMessage(); log.fatal(msg, e); throw new Exception(msg, e); } return type; }
From source file:org.wso2.carbon.social.sql.SocialDBInitilizer.java
public static String getDatabaseType(Connection conn) throws Exception { String type = null;/* www. j ava2s .co m*/ try { if (conn != null && (!conn.isClosed())) { DatabaseMetaData metaData = conn.getMetaData(); String databaseProductName = metaData.getDatabaseProductName(); if (databaseProductName.matches("(?i).*hsql.*")) { type = "hsql"; } else if (databaseProductName.matches("(?i).*derby.*")) { type = "derby"; } else if (databaseProductName.matches("(?i).*mysql.*")) { type = "mysql"; } else if (databaseProductName.matches("(?i).*oracle.*")) { type = "oracle"; } else if (databaseProductName.matches("(?i).*microsoft.*")) { type = "mssql"; } else if (databaseProductName.matches("(?i).*h2.*")) { type = "h2"; } else if (databaseProductName.matches("(?i).*db2.*")) { type = "db2"; } else if (databaseProductName.matches("(?i).*postgresql.*")) { type = "postgresql"; } else if (databaseProductName.matches("(?i).*openedge.*")) { type = "openedge"; } else if (databaseProductName.matches("(?i).*informix.*")) { type = "informix"; } else { String msg = "Unsupported database: " + databaseProductName + ". Database will not be created automatically by the WSO2 ES. " + "Please create the database using appropriate database scripts for " + "the SOCIAL database."; throw new Exception(msg); } } } catch (SQLException e) { String msg = "Failed to create Social database." + e.getMessage(); log.fatal(msg, e); throw new Exception(msg, e); } return type; }
From source file:ips1ap101.lib.core.db.util.DB.java
public static boolean setAutoCommit(Connection connection, boolean autoCommit) { if (connection != null) { try {// w w w .j a v a 2 s . co m if (!connection.isClosed()) { if (connection.getAutoCommit() == autoCommit) { Bitacora.trace("autocommit is already " + autoCommit); } else { Bitacora.trace("setting autocommit to " + autoCommit); connection.setAutoCommit(autoCommit); } return true; } } catch (SQLException ex) { Bitacora.logFatal(ex); } } return false; }
From source file:org.wso2.carbon.identity.core.persistence.IdentityDBInitializer.java
public static String getDatabaseType(Connection conn) throws IdentityRuntimeException { String type = null;//from w w w . ja v a2 s. com try { if (conn != null && (!conn.isClosed())) { DatabaseMetaData metaData = conn.getMetaData(); String databaseProductName = metaData.getDatabaseProductName(); if (databaseProductName.matches("(?i).*hsql.*")) { type = "hsql"; } else if (databaseProductName.matches("(?i).*derby.*")) { type = "derby"; } else if (databaseProductName.matches("(?i).*mysql.*")) { type = "mysql"; } else if (databaseProductName.matches("(?i).*oracle.*")) { type = "oracle"; } else if (databaseProductName.matches("(?i).*microsoft.*")) { type = "mssql"; } else if (databaseProductName.matches("(?i).*h2.*")) { type = "h2"; } else if (databaseProductName.matches("(?i).*db2.*")) { type = "db2"; } else if (databaseProductName.matches("(?i).*postgresql.*")) { type = "postgresql"; } else if (databaseProductName.matches("(?i).*openedge.*")) { type = "openedge"; } else if (databaseProductName.matches("(?i).*informix.*")) { type = "informix"; } else { String msg = "Unsupported database: " + databaseProductName + ". Database will not be created automatically by the WSO2 Identity Server. " + "Please create the database using appropriate database scripts for " + "the database."; throw new IdentityRuntimeException(msg); } } } catch (SQLException e) { String msg = "Failed to create identity database." + e.getMessage(); throw new IdentityRuntimeException(msg, e); } return type; }
From source file:org.wso2.carbon.utils.dbcreator.DatabaseCreator.java
/** * computes relatational database type using database name * * @return String/*ww w.j a va 2 s. c o m*/ * @throws Exception* */ public static String getDatabaseType(Connection conn) throws Exception { String type = null; try { if (conn != null && (!conn.isClosed())) { DatabaseMetaData metaData = conn.getMetaData(); String databaseProductName = metaData.getDatabaseProductName(); // if (databaseProductName.matches("(?i).*hsql.*")) { // type = "hsql"; // } else if (databaseProductName.matches("(?i).*derby.*")) { // type = "derby"; // } else if (databaseProductName.matches("(?i).*mysql.*")) { // type = "mysql"; // } else if (databaseProductName.matches("(?i).*oracle.*")) { // type = "oracle"; // } else if (databaseProductName.matches("(?i).*microsoft.*")) { // type = "mssql"; // } else if (databaseProductName.matches("(?i).*h2.*")) { // type = "h2"; // } else if (databaseProductName.matches("(?i).*db2.*")) { // type = "db2"; // } else if (databaseProductName.matches("(?i).*postgresql.*")) { // type = "postgresql"; // } else if (databaseProductName.matches("(?i).*openedge.*")) { // type = "openedge"; // } else { // String msg = "Unsupported database: " + databaseProductName + // ". Database will not be created automatically by the WSO2 Registry. " + // "Please create the database using appropriate database scripts for " + // "the database."; // throw new Exception(msg); // } type = getDatabaseType(databaseProductName); // avoid code duplication } } catch (SQLException e) { String msg = "Failed to create registry database." + e.getMessage(); log.fatal(msg, e); throw new Exception(msg, e); } return type; }
From source file:ips1ap101.lib.core.db.util.DB.java
public static boolean commit(Connection connection) { boolean autoCommit = true; /* evita el rollback si falla el getAutoCommit */ if (connection != null) { try {// w w w.j a va 2 s .c o m if (!connection.isClosed()) { autoCommit = connection.getAutoCommit(); if (!autoCommit) { connection.commit(); } return true; } } catch (SQLException ex) { Bitacora.logFatal(ex); if (!autoCommit) { rollback(connection); } } } return false; }