A datetime equivalent in java.sql ? (is there a java.sql.datetime ?)

The java.sql package has three date/time types:

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); 

Leave a Comment