Here you can find the source of close(ResultSet resultSet, Statement statement, Connection connection)
Parameter | Description |
---|---|
resultSet | Result set |
statement | Statement |
connection | Connection |
public static SQLException close(ResultSet resultSet, Statement statement, Connection connection)
//package com.java2s; /*/*w w w . jav a 2 s . c o m*/ // This software is subject to the terms of the Eclipse Public License v1.0 // Agreement, available at the following URL: // http://www.eclipse.org/legal/epl-v10.html. // You must accept the terms of that agreement to use this software. // // Copyright (C) 2001-2005 Julian Hyde // Copyright (C) 2005-2012 Pentaho and others // All Rights Reserved. */ import java.sql.*; public class Main { /** * Closes a JDBC result set, statement, and connection, ignoring any errors. * If any of them are null, that's fine. * * <p>If any of them throws a {@link SQLException}, returns the first * such exception, but always executes all closes.</p> * * @param resultSet Result set * @param statement Statement * @param connection Connection */ public static SQLException close(ResultSet resultSet, Statement statement, Connection connection) { SQLException firstException = null; if (resultSet != null) { try { if (statement == null) { statement = resultSet.getStatement(); } resultSet.close(); } catch (SQLException e) { firstException = e; } } if (statement != null) { try { statement.close(); } catch (SQLException e) { if (firstException == null) { firstException = e; } } } if (connection != null) { try { connection.close(); } catch (SQLException e) { if (firstException == null) { firstException = e; } } } return firstException; } }