Mark E Novak wrote:

> To insert formatted dates into an Oracle date field, in this instance, you
> would use to_date(dtfield, 'DD,MM,YYY'). I've used this successfully.
>
> You would use Oracle's to_char() to format a selected date field from Oracle
> as Oracle gives it to you in its default format, 01/MAY, 1999.
>

Dates are one of the places where not all databases use the same syntax in their
SQL, which can make switching from one to another more difficult than it needs
to be.  One way to reduce the pain, and avoid problems like this one, is to use
a PreparedStatement instead:

    Connection conn = ...;    // Acquire a JDBC connection
    PreparedStatement stmt =
      conn.prepareStatement("update customers set updated_date = ? where
customer_id = ?");
    java.sql.Date updateDate = new java.sql.Date(System.currentTimeMillis());
    stmt.setDate(1, updateDate);
    stmt.setLong(2, 123456);
    stmt.executeUpdate();
    stmt.close();

You don't have to worry about the syntax of this particular database's date
handling any more.  In the particular case of Oracle, you can also call PL/SQL
stored procedures (via a CallableStatement) and gain the same freedom.

Craig McClanahan

___________________________________________________________________________
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