Albert Yip wrote:

> Just wondering about how should I deal with dates when trying to insert data
> into db with prepared statements. I tried to use strings like "2001-05-16
> 10:10:10" but it keeps giving me error:
>
> java.sql.SQLException: ORA-01861: literal does not match format string
>
> any ideas? I would really appreciate it if someone can give a hand.


   I think you use something like:
<code>
...
PreparedStatement
   ps = con.prepareStatement("insert into my_table (name, date)"
                            +" values (?,?)"
                            );
ps.setString(1,"My Name");
ps.setString(2,"2001-05-16 10:10:10");
ps.executeUpdate();
...
</code>

   So, if my_table.date is of type DATE od DATETIME you must use setDate
or setTimestamp instead of setString. Look at the java.sql.*,
java.util.Date and java.util.GregorianCalendar javadoc.

   Personally, I don't like date/time manipulation in Java - it's too
complicated for me.

   Regards,

J.Ch.
--
Ing. Jozef Chocholacek                  Qbizm Technologies, Inc.
Chief Project Analyst                   ... the art of internet.
________________________________________________________________
Kralovopolska 139                          tel: +420 5 4124 2414
601 12 Brno, CZ      http://www.qbizm.com  fax: +420 5 4121 2696

___________________________________________________________________________
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