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

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)