Java SQL Update executeUpdate(Connection conn, String sql)

Here you can find the source of executeUpdate(Connection conn, String sql)

Description

execute Update

License

Apache License

Declaration

public static boolean executeUpdate(Connection conn, String sql) throws SQLException 

Method Source Code


//package com.java2s;
/*/*from w w  w.  jav a2s  . co  m*/
 * Copyright Red Hat, Inc. and/or its affiliates
 * and other contributors as indicated by the @author tags and
 * the COPYRIGHT.txt file distributed with this work.
 *
 * 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.
 */

import java.sql.Connection;

import java.sql.ResultSet;

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

public class Main {
    public static boolean executeUpdate(Connection conn, String sql) throws SQLException {

        Statement stmt = null;
        try {
            stmt = conn.createStatement();
            stmt.executeUpdate(sql);
        } finally {
            close(stmt);
        }
        return true;
    }

    public static void close(Connection conn) throws SQLException {
        close(null, null, conn);
    }

    public static void close(Statement stmt) throws SQLException {
        close(null, stmt, null);
    }

    public static void close(ResultSet rs) throws SQLException {
        close(rs, null, null);
    }

    public static void close(Statement stmt, Connection conn) throws SQLException {
        close(null, stmt, conn);
    }

    public static void close(ResultSet rs, Statement stmt) throws SQLException {
        close(rs, stmt, null);
    }

    public static void close(ResultSet rs, Statement stmt, Connection conn) throws SQLException {

        if (null != rs) {
            rs.close();
            rs = null;
        }

        if (null != stmt) {
            stmt.close();
            stmt = null;
        }

        if (null != conn) {
            conn.close();
            conn = null;
        }
    }
}

Related

  1. execUpdateQuery(Connection C, String query)
  2. ExecUpdateSql(Connection conn, String strSql)
  3. executeUpdate(Connection conn, String sql)
  4. executeUpdate(Connection conn, String sql)
  5. executeUpdate(Connection conn, String sql)
  6. executeUpdate(Connection conn, String sql, Object... parameters)
  7. executeUpdate(Connection connection, String query)
  8. executeUpdate(Connection connection, String statement)