Java SQL ResultSet Close closeResultAndStatement(Statement statement, ResultSet resultSet)

Here you can find the source of closeResultAndStatement(Statement statement, ResultSet resultSet)

Description

Helper method to close the JDBC interface(result set, statement).

License

Open Source License

Parameter

Parameter Description
statement the statement to be closed, could be null
resultSet the result set to be closed, could be null

Exception

Parameter Description
SQLException if any error occurs in this method

Declaration

public static void closeResultAndStatement(Statement statement, ResultSet resultSet) throws SQLException 

Method Source Code


//package com.java2s;

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

public class Main {
    /**//from   ww  w  .  ja  v  a 2s  . c om
     * <p>
     * Helper method to close the JDBC interface(result set, statement).
     * </p>
     *
     * @param statement the statement to be closed, could be null
     * @param resultSet the result set to be closed, could be null
     * @throws SQLException if any error occurs in this method
     */
    public static void closeResultAndStatement(Statement statement, ResultSet resultSet) throws SQLException {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
        } finally {
            closeStatement(statement);
        }
    }

    /**
     * <p>
     * Helper method to close the JDBC interface(statement).
     * </p>
     *
     * @param statement the statement to be closed, could be null
     * @throws SQLException if any error occurs in this method
     */
    public static void closeStatement(Statement statement) throws SQLException {
        if (statement != null) {
            statement.close();
        }
    }
}

Related

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