Code example for Connection

Methods: close

0
 
 
    public static Object execute(Connection conn, ConnectionCallback connectionCallBack) {
        try { 
            if (connectionCallBack != null && conn != null) {
                return connectionCallBack.doInConnection(conn);
            } 
        } 
        catch (SQLException e) {
            log.error("doInConnection failed", e);
        } 
        finally { 
            close(conn);
        } 
        return null; 
    } 
 
 
    public static Object execute(PreparedStatement pstmt, PreparedStatementCallback pstmtCallBack) {
        try { 
            if (pstmtCallBack != null && pstmt != null) {
                return pstmtCallBack.doInPreparedStatement(pstmt);
            } 
        } 
        catch (SQLException e) {
            log.error("doInPreparedStatement failed", e);
        } 
        finally { 
            close(pstmt);
        } 
        return null; 
    } 
 
 
    public static Object execute(ResultSet rs, ResultSetCallback rsCallback) {
        try { 
            if (rsCallback != null && rs != null) {
                return rsCallback.doInResultSet(rs);
            } 
        } 
        catch (SQLException e) {
            log.error("doInResultSet failed", e);
        } 
        finally { 
            close(rs);
        } 
        return null; 
    } 
 
 
    public static void close(PreparedStatement preparedStatement) {
        if (preparedStatement != null) {
            try { 
                preparedStatement.close();
            } 
            catch (SQLException e) {
                log.error("Close PreparedStatement failed", e);
            } 
 
        } 
    } 
 
 
    public static void close(ResultSet rs) {
        if (rs != null) {
            try { 
                rs.close();
            } 
            catch (SQLException ex) {
                log.error("Close ResultSet failed", ex);
            } 
        } 
    } 
 
 
    public static void close(Connection conn) {
        if (conn != null) {
            try { 
                conn.close();
            } 
            catch (SQLException ex) {
                log.error("Close connection failed", ex);
            } 
        }