Here you can find the source of executeUpdate(String parameterizedSQL, List
Parameter | Description |
---|---|
parameterizedSQL | a parameter |
values | a parameter |
conn | a parameter |
Parameter | Description |
---|---|
SQLException | an exception |
public static int executeUpdate(String parameterizedSQL, List<Object> values, Connection conn) throws SQLException
//package com.java2s; //License from project: Mozilla Public License import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; import java.util.List; public class Main { /**//from w ww. j a v a 2 s.c om * * @param parameterizedSQL * @param values * @param conn * @return int * @throws SQLException */ public static int executeUpdate(String parameterizedSQL, List<Object> values, Connection conn) throws SQLException { PreparedStatement pstmt = null; try { pstmt = prepareStatement(parameterizedSQL, values, conn); return pstmt.executeUpdate(); } finally { try { if (pstmt != null) pstmt.close(); } catch (SQLException e) { } } } /** * * @param parameterizedSQL * @param values * @param conn * @return PreparedStatement * @throws SQLException */ public static PreparedStatement prepareStatement(String parameterizedSQL, List<Object> values, Connection conn) throws SQLException { PreparedStatement pstmt = conn.prepareStatement(parameterizedSQL); for (int i = 0; values != null && i < values.size(); i++) { try { String val = (String) values.get(i); if (val != null && val.equals("NULL")) pstmt.setNull(i + 1, Types.NULL); else pstmt.setObject(i + 1, values.get(i)); } catch (ClassCastException e) { pstmt.setObject(i + 1, values.get(i)); } } return pstmt; } }