Java SQL Update executeUpdatePreparedStm(Connection conn, String preparedStm, Object... sqlParameters)

Here you can find the source of executeUpdatePreparedStm(Connection conn, String preparedStm, Object... sqlParameters)

Description

execute prepared sql statment

License

Open Source License

Parameter

Parameter Description
conn : the connection that the prepared statment will exceute in
preparedStm : prepared statment query e.g.: select * from tbl where col1= ?...
sqlParameters : list filled with the prepared statment parameters

Return

: int with number of updated rows

Declaration

public static int executeUpdatePreparedStm(Connection conn, String preparedStm, Object... sqlParameters)
        throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.*;

public class Main {
    /** execute prepared sql statment
     *@param conn : the connection that the prepared statment will exceute in
     *@param preparedStm : prepared statment query e.g.: select * from tbl where col1= ?...
     *@param sqlParameters : list filled with the prepared statment parameters
     *@return : int with number of updated rows
     *//*w w w.  j a  v a2  s  . c om*/
    public static int executeUpdatePreparedStm(Connection conn, String preparedStm, Object... sqlParameters)
            throws SQLException {
        //setNullableParameters(sqlParameters);
        int rs = 0;
        PreparedStatement prepStm = null;
        if (conn != null) {
            prepStm = conn.prepareStatement(preparedStm);
            if (sqlParameters != null) {
                for (int i = 1; i <= sqlParameters.length; i++) {
                    prepStm.setObject(i, sqlParameters[i - 1]);
                }
            }
            rs = prepStm.executeUpdate();
        }
        return rs;
    }
}

Related

  1. executeUpdate(PreparedStatement ps)
  2. executeUpdate(String parameterizedSQL, List values, Connection conn)
  3. executeUpdate(String queryStatement, Connection database)
  4. ExecuteUpdate(String sql, List paras)
  5. executeUpdateNoCommit(Connection c, String query)
  6. ExecuteUpdateQuery(String query, Connection con)
  7. executeUpdateSP(Connection conn, String spName, Object... sqlParameters)
  8. ExecuteUpdateStmt(Connection conn, PreparedStatement pstmt, PreparedStatement lockStatement, String tablename)

  9. HOME | Copyright © www.java2s.com 2016