Here you can find the source of prepareStatement(String parameterizedSQL, List
Parameter | Description |
---|---|
parameterizedSQL | a parameter |
values | a parameter |
conn | a parameter |
Parameter | Description |
---|---|
SQLException | an exception |
public static PreparedStatement prepareStatement(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 w w . j a v a 2 s . c o m * * @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; } }