Here you can find the source of formatStatement(PreparedStatement statement, List
public static void formatStatement(PreparedStatement statement, List<Object> values) throws SQLException
//package com.java2s; //License from project: Open Source License import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Timestamp; import java.util.Date; import java.util.List; import java.util.UUID; public class Main { public static void formatStatement(PreparedStatement statement, List<Object> values) throws SQLException { for (int i = 0; i < values.size(); ++i) { Object value = values.get(i); int index = i + 1; if (value instanceof String) { statement.setString(index, (String) value); } else if (value instanceof Date) { statement.setTimestamp(index, new Timestamp(((Date) value).getTime())); } else if (value instanceof Boolean) { statement.setBoolean(index, (Boolean) value); } else if (value instanceof Integer) { statement.setInt(index, (Integer) value); } else if (value instanceof Float) { statement.setFloat(index, (Float) value); } else if (value instanceof Double) { statement.setDouble(index, (Double) value); } else if (value instanceof UUID) { statement.setString(index, value.toString()); } else if (value instanceof Enum) { statement.setString(index, ((Enum) value).name()); } else { String name = value == null ? "null" : value.getClass().getName(); throw new IllegalArgumentException( "Unexpected type in '" + statement + "': " + name + ", " + values + ", ArrayIndex=" + i); }/*from w ww .j a v a 2s . co m*/ } } }