Here you can find the source of executeUpdate(List
Parameter | Description |
---|---|
sql | a parameter |
mapper | SQL execution parameters |
conn | a parameter |
pstmt | a parameter |
public static int executeUpdate(List<String> paramList, Connection conn, PreparedStatement pstmt)
//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; } }