Java examples for java.sql:PreparedStatement
Sets the parameter in the PreparedStatement with a timestamp (date and time) 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 { /**// w w w . ja va 2s. com * Sets the parameter in the statement with a timestamp (date and time) * 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 setNullableTimeStamp(PreparedStatement stmt, int paramIndex, Calendar cal) throws SQLException { if (cal == null) { stmt.setNull(paramIndex, Types.TIMESTAMP); } else { stmt.setTimestamp(paramIndex, new java.sql.Timestamp(cal .getTime().getTime())); } } }