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 Exception 

Method Source Code


//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 {
    public static boolean executeUpdate(Connection conn, String sql) throws Exception {

        Statement stmt = null;// w ww .j a va  2s.  co  m

        try {
            stmt = conn.createStatement();
            stmt.executeUpdate(sql);
        } catch (Exception e) {
            throw e;
        } finally {
            close(stmt);
        }

        return true;
    }

    public static void close(Connection conn) {

        if (null != conn) {
            try {
                conn.close();
                conn = null;
            } catch (SQLException e) {

            }
        }
    }

    public static void close(Statement stmt) {

        if (null != stmt) {
            try {
                stmt.close();
                stmt = null;
            } catch (SQLException e) {

            }
        }
    }

    public static void close(ResultSet rs, Statement stmt) {

        if (null != rs) {
            try {
                rs.close();
                rs = null;
            } catch (SQLException e) {
            }
        }

        if (null != stmt) {
            try {
                stmt.close();
                stmt = null;
            } catch (SQLException e) {
            }
        }
    }
}

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)
  9. executeUpdate(Connection dbConnection, String query)