Java examples for java.sql:PreparedStatement
Sets the parameter in the PreparedStatement with a date value, or null if the Calendar is null.
//package com.java2s; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; import java.util.Calendar; public class Main { /**//from www . ja v a 2 s . c om * Sets the parameter in the statement with a date value, or null if * the Calendar is null. * @param stmt The statement in which the parameter value is to be set. * @param paramIndex The index of the parameter to set. * @param cal The value to set (or null). * @throws SQLException Indicates an error setting the parameter. */ public static void setNullableDate(PreparedStatement stmt, int paramIndex, Calendar cal) throws SQLException { if (cal == null) { stmt.setNull(paramIndex, Types.DATE); } else { stmt.setDate(paramIndex, new java.sql.Date(cal.getTime() .getTime())); } } }