Java SQL ResultSet Close closeResources(Connection conn2, Statement statement, ResultSet rs)

Here you can find the source of closeResources(Connection conn2, Statement statement, ResultSet rs)

Description

close Resources

License

Apache License

Declaration

public static void closeResources(Connection conn2, Statement statement, ResultSet rs) 

Method Source Code


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

import java.sql.Connection;

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

public class Main {

    public static void closeResources(Connection conn1, PreparedStatement pstmt, ResultSet rs) {
        if (null != rs) {
            try {
                rs.close();//from  w  w w .  j  a va 2 s.  co m
            } catch (SQLException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            } finally {
                if (null != pstmt) {
                    try {
                        pstmt.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                        throw new RuntimeException(e);
                    } finally {
                        if (null != conn1) {
                            try {
                                conn1.close();
                            } catch (SQLException e) {
                                e.printStackTrace();
                                throw new RuntimeException(e);
                            }
                        }
                    }
                }
            }
        }
    }

    public static void closeResources(Connection conn2, Statement statement, ResultSet rs) {
        if (null != rs) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            } finally {
                if (null != statement) {
                    try {
                        statement.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                        throw new RuntimeException(e);
                    } finally {
                        if (null != conn2) {
                            try {
                                conn2.close();
                            } catch (SQLException e) {
                                e.printStackTrace();
                                throw new RuntimeException(e);
                            }
                        }
                    }
                }
            }
        }

    }
}

Related

  1. closeQuietly(ResultSet resultSet)
  2. closeQuietly(ResultSet rs)
  3. closeResource(Connection conn, Statement stmt, ResultSet rs)
  4. closeResources(Connection conn, Statement pstmt, ResultSet rs)
  5. closeResources(Connection conn, Statement stmt, ResultSet rs)
  6. closeResultAndStatement(Statement statement, ResultSet resultSet)
  7. closeResultSet(final ResultSet resultSet)
  8. closeResultset(ResultSet resultset)
  9. closeResultSet(ResultSet resultSet)