Java SQL Update executeUpdate(List paramList, Connection conn, PreparedStatement pstmt)

Here you can find the source of executeUpdate(List paramList, Connection conn, PreparedStatement pstmt)

Description

Don't forget We need to use this way to close pstmt and connection in persistence layer.

License

Apache License

Parameter

Parameter Description
sql a parameter
mapper SQL execution parameters
conn a parameter
pstmt a parameter

Declaration


public static int executeUpdate(List<String> paramList, Connection conn, PreparedStatement pstmt) 

Method Source Code


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

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.util.Iterator;
import java.util.List;

public class Main {
    /**/*from  w ww .  j av  a2s  .  c  o m*/
     * Don't forget We need to use this way to close pstmt and connection in persistence layer.
     * @param sql
     * @param mapper SQL execution parameters
     * @param conn
     * @param pstmt
     * @return
     */

    public static int executeUpdate(List<String> paramList, Connection conn, PreparedStatement pstmt) {
        int returnCode = -100;
        try {
            Iterator<String> paramIter = paramList.iterator();
            int i = 1;
            while (paramIter.hasNext()) {
                String eachParam = (String) paramIter.next();
                pstmt.setString(i, eachParam);
                i++;
            }
            returnCode = pstmt.executeUpdate();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return returnCode;
    }

    public static int executeUpdate(PreparedStatement pstmt) {
        int returnCode = -100;
        try {
            returnCode = pstmt.executeUpdate();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return returnCode;
    }
}

Related

  1. executeUpdate(Connection connection, String query)
  2. executeUpdate(Connection connection, String statement)
  3. executeUpdate(Connection dbConnection, String query)
  4. executeUpdate(final Connection conn, final String query)
  5. executeUpdate(final Connection conn, final String sqlStatmeent)
  6. executeUpdate(PreparedStatement preparedStatement, List paramList)
  7. executeUpdate(PreparedStatement ps)
  8. executeUpdate(String parameterizedSQL, List values, Connection conn)
  9. executeUpdate(String queryStatement, Connection database)

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