Example usage for java.sql Connection isClosed

List of usage examples for java.sql Connection isClosed

Introduction

In this page you can find the example usage for java.sql Connection isClosed.

Prototype

boolean isClosed() throws SQLException;

Source Link

Document

Retrieves whether this Connection object has been closed.

Usage

From source file:vitro.vspEngine.service.persistence.DBCommons.java

public Vector<DBRegisteredGateway> getRegisteredGatewayEntries() {
    Vector<DBRegisteredGateway> retVect = new Vector<DBRegisteredGateway>();
    java.sql.Connection conn = null;
    try {//from  w  w w .j  a va  2s. com
        Class.forName(jdbcdriverClassName).newInstance();
        conn = DriverManager.getConnection(connString, usrStr, pwdStr);
        String echomessage = "";
        if (!conn.isClosed()) {
            //echomessage =  "Successfully connected to "+ "MySQL server using TCP/IP...";
            Statement stmt = null;
            ResultSet rs = null;
            try {
                stmt = conn.createStatement();
                if (stmt.execute(
                        "SELECT idregisteredgateway, registeredName, friendlyName, friendlyDescription, ip, listeningport, lastadvtimestamp, disabled, FROM_UNIXTIME(lastadvtimestamp, \'%d/%m/%Y %H:%i:%s\') lastdate FROM `"
                                + dbSchemaStr + "`.`registeredgateway` ")) {
                    rs = stmt.getResultSet();
                }
                if (rs != null) {
                    while (rs.next()) {
                        int gateId = rs.getInt("idregisteredgateway");
                        String registeredName = rs.getString("registeredName") == null ? ""
                                : rs.getString("registeredName"); // this is the one used in registration messages
                        String friendlyName = rs.getString("friendlyName") == null ? ""
                                : rs.getString("friendlyName");
                        String friendlyDescription = rs.getString("friendlyDescription") == null ? ""
                                : rs.getString("friendlyDescription");
                        String gateIp = rs.getString("ip") == null ? "" : rs.getString("ip");
                        String gatePort = rs.getString("listeningport") == null ? ""
                                : rs.getString("listeningport");
                        int lastadvtimestampInt = rs.getInt("lastadvtimestamp");
                        String lastdate = rs.getString("lastdate") == null ? "N/A" : rs.getString("lastdate");
                        Boolean status = rs.getBoolean("disabled");
                        if (!registeredName.isEmpty() && !registeredName.equalsIgnoreCase("")) {
                            DBRegisteredGateway entryRegisterGateway = new DBRegisteredGateway(gateId,
                                    registeredName, friendlyName, friendlyDescription, gateIp, gatePort,
                                    lastadvtimestampInt, lastdate, status);
                            retVect.addElement(entryRegisterGateway);
                        }
                    }
                }
            } catch (SQLException ex) {
                // handle any errors
                System.out.println("SQLException: " + ex.getMessage());
                System.out.println("SQLState: " + ex.getSQLState());
                System.out.println("VendorError: " + ex.getErrorCode());
            } finally {
                // it is a good idea to release
                // resources in a finally{} block
                // in reverse-order of their creation
                // if they are no-longer needed
                if (rs != null) {
                    try {
                        rs.close();
                    } catch (SQLException sqlEx) {
                        System.out.println("SQLException on rs close(): " + sqlEx.getMessage());
                    } // ignore
                    rs = null;
                }
                if (stmt != null) {
                    try {
                        stmt.close();
                    } catch (SQLException sqlEx) {
                        System.out.println("SQLException on stmt close(): " + sqlEx.getMessage());
                    } // ignore
                    stmt = null;
                }
            }
        } else {
            echomessage = "Error accessing DB server...";
        }
        System.out.println(echomessage);
    } catch (Exception e) {
        System.err.println("Exception: " + e.getMessage());
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (SQLException e) {
        }
    }
    return retVect;
}

From source file:vitro.vspEngine.service.persistence.DBCommons.java

synchronized public void insertRegisteredGateway(String pGatewayRegisteredName, String pFriendlyName) {
    StringBuilder tmpIgnoredOutput = new StringBuilder();
    if (!isRegisteredGateway(pGatewayRegisteredName, tmpIgnoredOutput)) {
        if (pFriendlyName == null || pFriendlyName.trim().isEmpty()) {
            pFriendlyName = "unnamed island";
        }/*from  w ww .  j  a va2s. c  o  m*/
        java.sql.Connection conn = null;
        try {
            Class.forName(jdbcdriverClassName).newInstance();
            conn = DriverManager.getConnection(connString, usrStr, pwdStr);
            String echomessage = "";
            if (!conn.isClosed()) {
                //echomessage =  "Successfully connected to "+ "MySQL server using TCP/IP...";
                Statement stmt = null;
                ResultSet rs = null;
                try {
                    stmt = conn.createStatement();

                    if (stmt.execute("INSERT `" + dbSchemaStr
                            + "`.`registeredgateway`(registeredName, friendlyName) VALUES (\'"
                            + pGatewayRegisteredName + "\',\'" + pFriendlyName + "\')")) {
                        rs = stmt.getResultSet(); // TODO: this is not needed here...
                    }

                } catch (SQLException ex) {
                    // handle any errors
                    System.err.println("SQLException3: " + ex.getMessage());
                    System.err.println("SQLState3: " + ex.getSQLState());
                    System.err.println("VendorError3: " + ex.getErrorCode());
                } finally {
                    // it is a good idea to release
                    // resources in a finally{} block
                    // in reverse-order of their creation
                    // if they are no-longer needed
                    if (rs != null) {
                        try {
                            rs.close();
                        } catch (SQLException sqlEx) {
                        } // ignore
                        rs = null;
                    }
                    if (stmt != null) {
                        try {
                            stmt.close();
                        } catch (SQLException sqlEx) {
                        } // ignore
                        stmt = null;
                    }
                }
            } else {
                echomessage = "Error accessing DB server...";
            }
        } catch (Exception e) {
            System.err.println("Exception: " + e.getMessage());
        } finally {
            try {
                if (conn != null)
                    conn.close();
            } catch (SQLException e) {
            }
        }
    }
}

From source file:vitro.vspEngine.service.persistence.DBCommons.java

synchronized public void updateStatusUser(String pUserRegisteredName) {
    java.sql.Connection conn = null;
    try {// w  ww.  j  av  a 2  s.c om
        String echomessage = "";
        Class.forName(jdbcdriverClassName).newInstance();
        conn = DriverManager.getConnection(connString, usrStr, pwdStr);
        if (!conn.isClosed()) {
            Statement stmt = null;
            ResultSet rs = null;
            try {
                stmt = conn.createStatement();
                if (stmt.execute(
                        "SELECT idusers, passwd, login, email, idrole, role_name, lastadvtimestamp, disabled, FROM_UNIXTIME(lastadvtimestamp, \'%d/%m/%Y %H:%i:%s\') lastdate FROM vitrofrontenddb.roles AS r JOIN (vitrofrontenddb.userinrolesmr as ur JOIN vitrofrontenddb.users AS u ON u.idusers = ur.iduser) ON r.idroles=ur.idrole ")) {
                    rs = stmt.getResultSet();
                }
                if (rs != null) {
                    while (rs.next()) {
                        int userId = rs.getInt("idusers");
                        String passwd = rs.getString("passwd") == null ? "" : rs.getString("passwd"); // this is the one used in registration messages
                        String loginName = rs.getString("login") == null ? "" : rs.getString("login");
                        String emailAddress = rs.getString("email") == null ? "" : rs.getString("email");
                        String role_name = rs.getString("role_name") == null ? "" : rs.getString("role_name");
                        int role = rs.getInt("idrole");
                        int lastadvtimestampInt = rs.getInt("lastadvtimestamp");
                        String lastdate = rs.getString("lastdate") == null ? "N/A" : rs.getString("lastdate");
                        Boolean status = rs.getBoolean("disabled");
                        if (loginName.equalsIgnoreCase(pUserRegisteredName)) {
                            if (status == false) {
                                if (stmt.execute(
                                        "UPDATE `" + dbSchemaStr + "`.`users` SET disabled = 1  WHERE login=\'"
                                                + pUserRegisteredName + "\'")) {
                                    rs = stmt.getResultSet(); // TODO: this is not needed here...
                                }
                            } else {
                                if (stmt.execute(
                                        "UPDATE `" + dbSchemaStr + "`.`users` SET disabled = 0  WHERE login=\'"
                                                + pUserRegisteredName + "\'")) {
                                    rs = stmt.getResultSet(); // TODO: this is not needed here...
                                }
                            }
                            break;
                        }
                    }
                }

            } catch (SQLException ex) {
                // handle any errors
                System.err.println("SQLException3: " + ex.getMessage());
                System.err.println("SQLState3: " + ex.getSQLState());
                System.err.println("VendorError3: " + ex.getErrorCode());
            } finally {
                // it is a good idea to release
                // resources in a finally{} block
                // in reverse-order of their creation
                // if they are no-longer needed
                if (rs != null) {
                    try {
                        rs.close();
                    } catch (SQLException sqlEx) {
                    } // ignore
                    rs = null;
                }
                if (stmt != null) {
                    try {
                        stmt.close();
                    } catch (SQLException sqlEx) {
                    } // ignore
                    stmt = null;
                }
            }
        } else {
            echomessage = "Error accessing DB server...";
        }
        // DEBUG
        //System.out.println(echomessage);
    } catch (Exception e) {
        System.err.println("Exception: " + e.getMessage());
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (SQLException e) {
        }
    }
}

From source file:vitro.vspEngine.service.persistence.DBCommons.java

synchronized public void insertUser(String ploginName, String pemailAddress, String ppasswd, String proleName) {
    java.sql.Connection conn = null;
    try {//from w w w .ja  va 2 s  . c  om
        String echomessage = "";
        Class.forName(jdbcdriverClassName).newInstance();
        conn = DriverManager.getConnection(connString, usrStr, pwdStr);
        if (!conn.isClosed()) {
            Statement stmt = null;
            ResultSet rs = null;
            try {
                stmt = conn.createStatement();
                if (stmt.execute(
                        "SELECT * FROM `" + dbSchemaStr + "`.`users` where `login`=\'" + ploginName + "\'")) {
                    rs = stmt.getResultSet();
                }
                if (rs == null) {
                    int refRoleId = -1;
                    int refUserId = -1;

                    if (stmt.execute("START TRANSACTION")) {
                        rs = stmt.getResultSet(); // TODO: this is not needed here...
                    }
                    if (stmt.execute("INSERT INTO `" + dbSchemaStr
                            + "`.`users` (`login`, `email`, `passwd`, `lastadvtimestamp`, `disabled`) VALUES (\'"
                            + ploginName + "\',\'" + pemailAddress + "\',\'" + ppasswd + "\',0,0)")) {
                        rs = stmt.getResultSet(); // TODO: this is not needed here...
                    }
                    if (stmt.execute("SELECT `idusers` from `" + dbSchemaStr + "`.`users` where `login`= \'"
                            + ploginName + "\'")) {
                        rs = stmt.getResultSet();
                        refUserId = rs.getInt("idusers");
                    }
                    if (stmt.execute("SELECT `idroles` from `" + dbSchemaStr + "`.`roles` where `role_name`= \'"
                            + proleName + "\'")) {
                        rs = stmt.getResultSet();
                        refRoleId = rs.getInt("idroles");
                    }
                    if (stmt.execute(
                            "INSERT INTO `" + dbSchemaStr + "`.`userinrolesmr` (`idrole`, `iduser`) VALUES (\'"
                                    + refRoleId + "\',\'" + refUserId + "\')")) {
                        rs = stmt.getResultSet(); // TODO: this is not needed here...
                    }
                    if (stmt.execute("COMMIT")) {
                        rs = stmt.getResultSet(); // TODO: this is not needed here...
                    }

                } else
                    System.err.println("The inserted value already exists");

            } catch (SQLException ex) {
                // handle any errors
                System.err.println("SQLException3: " + ex.getMessage());
                System.err.println("SQLState3: " + ex.getSQLState());
                System.err.println("VendorError3: " + ex.getErrorCode());
            } finally {
                // it is a good idea to release
                // resources in a finally{} block
                // in reverse-order of their creation
                // if they are no-longer needed
                if (rs != null) {
                    try {
                        rs.close();
                    } catch (SQLException sqlEx) {
                    } // ignore
                    rs = null;
                }
                if (stmt != null) {
                    try {
                        stmt.close();
                    } catch (SQLException sqlEx) {
                    } // ignore
                    stmt = null;
                }
            }
        } else {
            echomessage = "Error accessing DB server...";
        }
        // DEBUG
        //System.out.println(echomessage);
    } catch (Exception e) {
        System.err.println("Exception: " + e.getMessage());
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (SQLException e) {
        }
    }
}

From source file:vitro.vspEngine.service.persistence.DBCommons.java

synchronized public void updateStatus(String pGatewayRegisteredName) {
    java.sql.Connection conn = null;
    try {//w w  w  . j a  va  2  s.  c  o  m
        String echomessage = "";
        Class.forName(jdbcdriverClassName).newInstance();
        conn = DriverManager.getConnection(connString, usrStr, pwdStr);
        if (!conn.isClosed()) {
            Statement stmt = null;
            ResultSet rs = null;
            try {
                stmt = conn.createStatement();
                if (stmt.execute(
                        "SELECT idregisteredgateway, registeredName, friendlyName, friendlyDescription, ip, listeningport, lastadvtimestamp, disabled, FROM_UNIXTIME(lastadvtimestamp, \'%d/%m/%Y %H:%i:%s\') lastdate FROM `"
                                + dbSchemaStr + "`.`registeredgateway` ")) {
                    rs = stmt.getResultSet();
                }
                if (rs != null) {
                    while (rs.next()) {
                        int gateId = rs.getInt("idregisteredgateway");
                        String registeredName = rs.getString("registeredName") == null ? ""
                                : rs.getString("registeredName"); // this is the one used in registration messages
                        String friendlyName = rs.getString("friendlyName") == null ? ""
                                : rs.getString("friendlyName");
                        String friendlyDescription = rs.getString("friendlyDescription") == null ? ""
                                : rs.getString("friendlyDescription");
                        String gateIp = rs.getString("ip") == null ? "" : rs.getString("ip");
                        String gatePort = rs.getString("listeningport") == null ? ""
                                : rs.getString("listeningport");
                        int lastadvtimestampInt = rs.getInt("lastadvtimestamp");
                        String lastdate = rs.getString("lastdate") == null ? "N/A" : rs.getString("lastdate");
                        Boolean status = rs.getBoolean("disabled");
                        if (registeredName.equalsIgnoreCase(pGatewayRegisteredName)) {
                            if (status == false) {
                                if (stmt.execute("UPDATE `" + dbSchemaStr
                                        + "`.`registeredgateway` SET disabled = 1  WHERE registeredName=\'"
                                        + pGatewayRegisteredName + "\'")) {
                                    rs = stmt.getResultSet(); // TODO: this is not needed here...
                                }
                            } else {
                                if (stmt.execute("UPDATE `" + dbSchemaStr
                                        + "`.`registeredgateway` SET disabled = 0  WHERE registeredName=\'"
                                        + pGatewayRegisteredName + "\'")) {
                                    rs = stmt.getResultSet(); // TODO: this is not needed here...
                                }
                            }
                            break;
                        }
                    }
                }

            } catch (SQLException ex) {
                // handle any errors
                System.err.println("SQLException3: " + ex.getMessage());
                System.err.println("SQLState3: " + ex.getSQLState());
                System.err.println("VendorError3: " + ex.getErrorCode());
            } finally {
                // it is a good idea to release
                // resources in a finally{} block
                // in reverse-order of their creation
                // if they are no-longer needed
                if (rs != null) {
                    try {
                        rs.close();
                    } catch (SQLException sqlEx) {
                    } // ignore
                    rs = null;
                }
                if (stmt != null) {
                    try {
                        stmt.close();
                    } catch (SQLException sqlEx) {
                    } // ignore
                    stmt = null;
                }
            }
        } else {
            echomessage = "Error accessing DB server...";
        }
        // DEBUG
        //System.out.println(echomessage);
    } catch (Exception e) {
        System.err.println("Exception: " + e.getMessage());
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (SQLException e) {
        }
    }
}

From source file:com.generalbioinformatics.rdf.VirtuosoConnection.java

/**
 * Execute a SPARQL query. The query will be based directly to Virtuoso, so all the
 * virtuoso sparql syntax quirks can be used.
 * <p>/*from  w w w .  ja  v  a2 s .c  o m*/
 * If you set any prefixes with setPrefixes, they will be included in this query.
 * <p>
 * If you set any cache dir, the query will be saved to File on the first run, 
 * and retrieved on the second run. 
 */
public RecordStream _sparqlSelectDirect(String query) throws StreamException {
    Connection con = null;
    Statement st = null;
    RecordStream rs = null;
    try {
        con = getConnection();
        st = con.createStatement();
        ResultSet result = executeQuery(st, "SPARQL " + prefixes + " " + query);
        rs = new VirtuosoRecordStream(result, st, isManagedConnection() ? con : null);
        return rs;
    } catch (Exception ex) {
        // if we failed to create the stream, clean up and rethrow
        try {
            if (rs != null)
                rs.close();
            if (st != null && !st.isClosed())
                st.close();
            if (isManagedConnection() && !con.isClosed())
                con.close();
        } catch (SQLException inner) {
            /* ignore */ }

        throw new StreamException(ex);
    }
}

From source file:vitro.vspEngine.service.persistence.DBCommons.java

public DBRegisteredGateway getRegisteredGateway(String pGwId) {
    DBRegisteredGateway retRegGw = null;
    if (pGwId != null && !pGwId.isEmpty()) {
        java.sql.Connection conn = null;
        try {//from w w  w.j  a  va2  s.  co  m
            Class.forName(jdbcdriverClassName).newInstance();
            conn = DriverManager.getConnection(connString, usrStr, pwdStr);
            String echomessage = "";
            if (!conn.isClosed()) {
                //echomessage =  "Successfully connected to "+ "MySQL server using TCP/IP...";
                Statement stmt = null;
                ResultSet rs = null;
                try {
                    stmt = conn.createStatement();
                    if (stmt.execute(
                            "SELECT idregisteredgateway, registeredName, friendlyName, friendlyDescription, ip, listeningport, lastadvtimestamp, disabled, FROM_UNIXTIME(lastadvtimestamp, \'%d/%m/%Y %H:%i:%s\') lastdate FROM `"
                                    + dbSchemaStr + "`.`registeredgateway` WHERE registeredName=\'" + pGwId
                                    + "\'")) {
                        rs = stmt.getResultSet();
                    }
                    if (rs != null) {
                        while (rs.next()) {
                            int gateId = rs.getInt("idregisteredgateway");
                            String registeredName = rs.getString("registeredName") == null ? ""
                                    : rs.getString("registeredName"); // this is the one used in registration messages
                            String friendlyName = rs.getString("friendlyName") == null ? ""
                                    : rs.getString("friendlyName");
                            String friendlyDescription = rs.getString("friendlyDescription") == null ? ""
                                    : rs.getString("friendlyDescription");
                            String gateIp = rs.getString("ip") == null ? "" : rs.getString("ip");
                            String gatePort = rs.getString("listeningport") == null ? ""
                                    : rs.getString("listeningport");
                            int lastadvtimestampInt = rs.getInt("lastadvtimestamp");
                            String lastdate = rs.getString("lastdate") == null ? "N/A"
                                    : rs.getString("lastdate");
                            Boolean status = rs.getBoolean("disabled");
                            if (!registeredName.isEmpty() && !registeredName.equalsIgnoreCase("")) {
                                retRegGw = new DBRegisteredGateway(gateId, registeredName, friendlyName,
                                        friendlyDescription, gateIp, gatePort, lastadvtimestampInt, lastdate,
                                        status);
                            }
                            break; // we only need one result, so break here
                        }
                    }
                } catch (SQLException ex) {
                    // handle any errors
                    System.out.println("SQLException: " + ex.getMessage());
                    System.out.println("SQLState: " + ex.getSQLState());
                    System.out.println("VendorError: " + ex.getErrorCode());
                } finally {
                    // it is a good idea to release
                    // resources in a finally{} block
                    // in reverse-order of their creation
                    // if they are no-longer needed
                    if (rs != null) {
                        try {
                            rs.close();
                        } catch (SQLException sqlEx) {
                            System.out.println("SQLException on rs close(): " + sqlEx.getMessage());
                        } // ignore
                        rs = null;
                    }
                    if (stmt != null) {
                        try {
                            stmt.close();
                        } catch (SQLException sqlEx) {
                            System.out.println("SQLException on stmt close(): " + sqlEx.getMessage());
                        } // ignore
                        stmt = null;
                    }
                }
            } else {
                echomessage = "Error accessing DB server...";
            }
            System.out.println(echomessage);
        } catch (Exception e) {
            System.err.println("Exception: " + e.getMessage());
        } finally {
            try {
                if (conn != null)
                    conn.close();
            } catch (SQLException e) {
            }
        }
    }
    return retRegGw;
}

From source file:com.cloudera.sqoop.manager.OracleManagerTest.java

public void testPurgeClosedConnections() throws Exception {
    // Ensure that after an Oracle ConnManager releases any connections
    // back into the cache (or closes them as redundant), it does not
    // attempt to re-use the closed connection.

    SqoopOptions options = new SqoopOptions(OracleUtils.CONNECT_STRING, TABLE_NAME);
    OracleUtils.setOracleAuth(options);//from  w  w w.j  ava 2 s .  c o  m

    // Create a connection manager, use it, and then recycle its connection
    // into the cache.
    ConnManager m1 = new OracleManager(options);
    Connection c1 = m1.getConnection();
    PreparedStatement s = c1.prepareStatement("SELECT 1 FROM dual", ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = null;
    try {
        rs = s.executeQuery();
        rs.close();
    } finally {
        s.close();
    }

    ConnManager m2 = new OracleManager(options);
    Connection c2 = m2.getConnection(); // get a new connection.

    m1.close(); // c1 should now be cached.

    // Use the second connection to run a statement.
    s = c2.prepareStatement("SELECT 2 FROM dual", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    try {
        rs = s.executeQuery();
        rs.close();
    } finally {
        s.close();
    }

    m2.close(); // c2 should be discarded (c1 is already cached).

    // Try to get another connection from m2. This should result in
    // a completely different connection getting served back to us.
    Connection c2a = m2.getConnection();

    assertFalse(c1.isClosed());
    assertTrue(c2.isClosed());
    assertFalse(c2a.isClosed());

    s = c2a.prepareStatement("SELECT 3 FROM dual", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    try {
        rs = s.executeQuery();
        rs.close();
    } finally {
        s.close();
    }

    m2.close(); // Close the manager's active connection again.
}

From source file:com.ah.be.communication.BusinessUtil.java

private static String[] getDBSettings() throws SQLException {
    String[] dbSettings = new String[5];
    Connection con = null;

    try {/*  w  ww.ja  va  2 s . c  om*/
        con = QueryUtil.getConnection();
        DatabaseMetaData mData = con.getMetaData();
        String[] urls = DBOperationUtil.parseJDBCUrl(mData.getURL());
        if (urls != null && urls.length == 3) {
            dbSettings[0] = urls[0];
            dbSettings[1] = urls[1];
            dbSettings[2] = urls[2];
            dbSettings[3] = System.getProperty("hm.connection.username");
            dbSettings[4] = System.getProperty("hm.connection.password");
        }
        return dbSettings;
    } finally {
        if (con != null && !con.isClosed()) {
            try {
                con.close();
            } catch (SQLException e) {
                log.error("Connection close error.", e);
            }
        }
    }
}

From source file:edu.uga.cs.fluxbuster.db.PostgresDBInterface.java

/**
 * @see edu.uga.cs.fluxbuster.db.DBInterface#executeQueryWithResult(java.lang.String)
 *//*from ww w .  j  av a 2s  .  com*/
@Override
public ResultSet executeQueryWithResult(String query) {
    ResultSet retval = null;
    Connection con = null;
    Statement stmt = null;
    try {
        con = this.getConnection();
        con.setAutoCommit(false);
        stmt = con.createStatement();
        retval = stmt.executeQuery(query);
        con.commit();
    } catch (SQLException e) {
        retval = null;
        if (log.isErrorEnabled()) {
            log.error(query, e);
        }
        try {
            if (con != null && !con.isClosed()) {
                con.rollback();
            }
        } catch (SQLException e1) {
            if (log.isErrorEnabled()) {
                log.error("Error during rollback.", e1);
            }
        }
    } finally {
        try {
            if (con != null && !con.isClosed()) {
                con.setAutoCommit(true);
                con.close();
            }
        } catch (SQLException e) {
            if (log.isErrorEnabled()) {
                log.error("Error during close.", e);
            }
        }
    }
    return retval;
}