Java SQL Update executeUpdate(Connection conn, String sql, Object... parameters)

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

Description

execute Update

License

Apache License

Declaration

public static int executeUpdate(Connection conn, String sql, Object... parameters) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.*;

public class Main {
    public static int executeUpdate(Connection conn, String sql, Object... parameters) throws SQLException {
        PreparedStatement stmt = null;
        int result = -1;
        try {//from   ww  w.jav a 2s .c o  m
            stmt = conn.prepareStatement(sql);
            bindParams(stmt, parameters);
            result = stmt.executeUpdate();
        } finally {
            if (stmt != null) {
                stmt.close();
            }
        }
        return result;
    }

    private static void bindParams(PreparedStatement stmt, Object... parameters) throws SQLException {
        for (int i = 0; i < parameters.length; i++) {
            stmt.setObject(i + 1, parameters[i]);
        }
    }
}

Related

  1. ExecUpdateSql(Connection conn, String strSql)
  2. executeUpdate(Connection conn, String sql)
  3. executeUpdate(Connection conn, String sql)
  4. executeUpdate(Connection conn, String sql)
  5. executeUpdate(Connection conn, String sql)
  6. executeUpdate(Connection connection, String query)
  7. executeUpdate(Connection connection, String statement)
  8. executeUpdate(Connection dbConnection, String query)
  9. executeUpdate(final Connection conn, final String query)