Here you can find the source of commitAndClose(Connection connection)
Parameter | Description |
---|---|
connection | a parameter |
Parameter | Description |
---|---|
SQLException | an exception |
public static void commitAndClose(Connection connection) throws SQLException
//package com.java2s; //License from project: Apache License import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main { /**/*from www.j a v a 2 s . c o m*/ * Commit and close. * * @param connection * @throws SQLException */ public static void commitAndClose(Connection connection) throws SQLException { try { commit(connection); } finally { close(connection); } } /** * Commits changes that exists in the {@link Connection}. * * @param connection * @throws SQLException */ public static void commit(Connection connection) throws SQLException { if (connection != null && !connection.getAutoCommit()) { connection.commit(); } } /** * Closes a {@link Connection}. * * @param connection * @throws SQLException */ public static void close(Connection connection) throws SQLException { if (connection != null) { connection.close(); connection = null; } } /** * Closes a {@link Statement}/{@link PreparedStatement}/{@link CallableStatement}. * * @param statement * @throws SQLException */ public static void close(Statement statement) throws SQLException { if (statement != null) { statement.close(); statement = null; } } /** * Closes a {@link ResultSet}. * * @param resultSet * @throws SQLException */ public static void close(ResultSet resultSet) throws SQLException { if (resultSet != null) { resultSet.close(); resultSet = null; } } }