The java.sql.Date class does not handle hours, minutes or seconds. If you need
to insert the exact time into a SQL database I suggest create a string the
database recognizes and then inserting the string. This works:

////////////////////////
    java.util.Date utilDate = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy hh:mmaa");
    String stringDate = sdf.format(utilDate).toString();

............. later ....

    pstmt.setString(1, stringDate);
//////////////////////////

where pstmt is a prepared statement (in this case)

To extract the date you need to read it from the database as a string and
extract it into its seperate components and construct a new Date.

Why doesn't java.sql.Date handle time? Couldn't database compatablity have been
handled in the jdbc driver being used?

brian

Gautam Batra wrote:

> First get the current date from
>
> java.util.Date
>
> Date currentDate=new Date();
>
> then convert it into long type.....
>
> then pass that as a parameter to the java.sql.Date constructor
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to