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

Reply via email to