The java.sql package has three date/time types:
java.sql.Date
– A date only (no time part)java.sql.Time
– A time only (no date part)java.sql.Timestamp
– Both date and time
You want the last one: java.sql.Timestamp
.
If you are using these types, you don’t need to call a specific setter; just use:
java.util.Date date = new Date();
Object param = new java.sql.Timestamp(date.getTime());
// The JDBC driver knows what to do with a java.sql type:
preparedStatement.setObject(param);