Java SQL ResultSet Close closeAll(Connection conn, Statement stmt, ResultSet rs)

Here you can find the source of closeAll(Connection conn, Statement stmt, ResultSet rs)

Description

Description:TODO

License

Apache License

Parameter

Parameter Description
conn a parameter
stmt a parameter
rs a parameter

Declaration

protected static void closeAll(Connection conn, Statement stmt, ResultSet rs) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.CallableStatement;
import java.sql.Connection;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    /**/*from ww  w  .  jav a  2  s . co m*/
     * <p>Description:TODO</p>
     * @param conn
     * @param pstmt
     * @param rs 
     * @author lijw
     * @since 2013-3-5
     */
    protected static void closeAll(Connection conn, PreparedStatement pstmt, ResultSet rs) {
        if (null != rs) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                rs = null;
            }
        }
        if (null != pstmt) {
            try {
                pstmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                pstmt = null;
            }
        }
        if (null != conn) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                conn = null;
            }
        }
    }

    /**
     * <p>Description:TODO</p>
     * @param conn
     * @param stmt
     * @param rs 
     * @author lijw
     * @since 2013-3-5
     */
    protected static void closeAll(Connection conn, Statement stmt, ResultSet rs) {
        if (null != rs) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                rs = null;
            }
        }
        if (null != stmt) {
            try {
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                stmt = null;
            }
        }
        if (null != conn) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                conn = null;
            }
        }
    }

    /**
     * <p>Description:TODO</p>
     * @param conn
     * @param pstmt 
     * @author lijw
     * @since 2013-3-5
     */
    protected static void closeAll(Connection conn, PreparedStatement pstmt) {
        if (null != pstmt) {
            try {
                pstmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                pstmt = null;
            }
        }
        if (null != conn) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                conn = null;
            }
        }
    }

    /**
     * <p>Description:TODO</p>
     * @param conn
     * @param pstmt 
     * @author lijw
     * @since 2013-3-5
     */
    protected static void closeAll(Connection conn, CallableStatement cs) {
        if (null != cs) {
            try {
                cs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                cs = null;
            }
        }
        if (null != conn) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                conn = null;
            }
        }
    }
}

Related

  1. close(ResultSet rs, Statement stmt, Connection con)
  2. close(ResultSet rs, Statement stmt, Connection con)
  3. close(ResultSet rs, Statement stmt, Connection con)
  4. close(Statement statement, ResultSet resultSet)
  5. closeAll(Connection con, PreparedStatement ps, ResultSet rs)
  6. closeAll(Connection conn, Statement stmt, ResultSet rs)
  7. closeAll(ResultSet rs)
  8. closeAll(ResultSet rs, Statement st, Connection conn)
  9. closeAll(ResultSet rs, Statement stmt, Connection conn)