Here you can find the source of commitAndClose(Connection conn)
Connection
then closes it, avoid closing if null.
public static void commitAndClose(Connection conn) throws SQLException
//package com.java2s; /*/*from w w w.j a va 2s.c om*/ * @(#)$Id$ * * Copyright 2003-2004 The Apache Software Foundation * Copyright 2006-2008 Makoto YUI * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Contributors: * Makoto YUI - ported from jakarta commons DBUtils */ import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main { /** * Commits a <code>Connection</code> then closes it, avoid closing if null. */ public static void commitAndClose(Connection conn) throws SQLException { if (conn == null) { throw new IllegalArgumentException( "Given connection is null although trying to commit the transaction."); } try { conn.commit(); } finally { conn.close(); } } /** * Close a <code>ResultSet</code>, avoid closing if null. */ public static void close(ResultSet rs) throws SQLException { if (rs != null) { rs.close(); } } /** * Close a <code>Statement</code>, avoid closing if null. */ public static void close(Statement stmt) throws SQLException { if (stmt != null) { stmt.close(); } } }