You need to be careful because different database request the format in
different ways.  I do teh following.

                        Calendar currentCalendar = Calendar.getInstance();
                        int a = currentCalendar.get(Calendar.YEAR);
                        int b = currentCalendar.get(Calendar.MONTH);
                        b++; //Need to increment the month because it is zero-based
                        int c = currentCalendar.get(Calendar.DATE);
                        String currentDate = a + "-" + b + "-" + c; //Format the date 
for DB2


Does that seem absurd?

Eytan

> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
> Martin Kuba
> Sent: Tuesday, July 13, 1999 9:40 AM
> To: [EMAIL PROTECTED]
> Subject: Re: How do I set the current date thru JDBC.
>
>
> Brian Silberbauer wrote:
> >
> > 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)
>
> NO ! You should let the JDBC driver do this job. If you need
> to store exact time and date use the type java.sql.Timestamp:
>
> java.util.Date now = new java.util.Date();
> java.sql.Timestamp ts = new java.sql.Timestamp(now.getTime());
> ...
> pstmt.setTimestamp(1,ts);
>
> Martin
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    INET, a.s.                          Mgr. Martin Kuba
> Kralovopolska 139                  e-mail: [EMAIL PROTECTED]
>   601 12 Brno                      WWW: http://www.inet.cz/~makub/
>  Czech Republic                    tel: +420-5-41242414/33
> --------------------------------------------------------------------
> PGP fingerprint = D8 57 47 E5 36 D2 C1 A1  C3 48 B2 59 00 58 42 27
>  http://wwwkeys.cz.pgp.net:11371/pks/lookup?op=index&search=makub
> --------------------------------------------------------------------
>
> __________________________________________________________________
> _________
> 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

Reply via email to