String -> java.util.Date -> java.sql.Date (with time stamp) String -> java.util.Date -> java.sql.Date (with time stamp) sql sql

String -> java.util.Date -> java.sql.Date (with time stamp)


java.sql.Date doesn't have the time.

Use java.sql.Timestamp instead.


I might be very late to answer this question but I think it might be helpful.

As stated by 'Felipe Fonseca', I converted the util date to sql date as follows:

public static java.sql.Timestamp convertToSqlDateTime(Date utilDate){    return new java.sql.Timestamp(utilDate.getTime());}

Normally, java.sql.Date only returns Date value and time will be discarded. So, in order to get time also, java.sql.TimeStamp must be used.

TimeStamp Constructs a Timestamp object using a milliseconds time value. The integral seconds are stored in the underlying date value; the fractional seconds are stored in the nanos field of the Timestamp object.

For this purpose, utilDate.getTime() is used to return the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date Object.

If we want only java.sql.Date, we can do:

public static java.sql.Date convertToSqlDate(Date utilDate){    return new java.sql.Date(utilDate.getTime());}


I have completely given up on using Java's standard Date classes, for exactly the reasons you list.

I've been using Joda Time for a while now, and have found it a lot simpler.