If you use a prepared statement, you don't have to do all these contortions.
PreparedStatement pstmt = con.prepareStatement("select * from employees
where hire_date > ?");
pstmt.setDate(1,new Date());
This is required to work on all JDBC drivers so is much more portable than
looking up each databases date to string conversion and handling it
yourself.
(*Chris*)
----- Original Message -----
From: Brian Silberbauer <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 13, 1999 4:35 AM
Subject: Re: How do I set the current date thru JDBC.
> 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
>
___________________________________________________________________________
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