Re: How to query a Date Column in SQL

From: Lee Fesperman (firstsql_at_ix.netcom.com)
Date: 08/19/04


Date: Wed, 18 Aug 2004 23:25:07 GMT

Laura P wrote:
>
> I am in the process of refactoring a Java application which uses JDBC
> to talk to Oracle and MySQL. The old way used to have a DateTime
> field that was represented in the database as a text field, a typical
> query on this field would be: "Select * from Table1 where DateTime <=
> '2004/08/17 09:00:30'".
>
> In the new database schema, the DateTime field is represented as a
> Date field. My problem is that I have to parse my query text (which
> is not SQL :( ) and create a String from that, which is valid SQL.
> This happens in a different part of the application to the actual
> database connection, so I cannot use a PreparedStatement and insert
> the java.sql.Date value that way. I have found some information about
> sql date operators such as DATEDIFF, but not enough to make use of
> them, and I was not sure if these would work through the JDBC driver
> even if I managed to get them working...
>
> I would be very grateful for any information anyone has on this - I
> can't believe it is as difficult as I have found it today to create a
> data query SQL string!

Have you tried using the {d ...} escape sequence? It uses a standard date form that is
easy to create with DateFormat classes in java.text. Hopefully, both the Oracle and
MySQL JDBC drivers will support the escape sequence.

-- 
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS  (http://www.firstsql.com)


Relevant Pages

  • DBSync for Oracle and MySQL 1.0.0
    ... DBSync for Oracle and MySQL is a database synchronization tool ... also applicable for MySQL database replication to another MySQL ...
    (comp.software.shareware.announce)
  • Re: Problem with SQLLoader Date columns and JDBC access
    ... Oracle 9i database. ... note that the column in the database is defined as DATE not as TIMESTAMP. ... But when I try to access this column via JDBC using getTimestampthe ... substr function. ...
    (comp.databases.oracle.misc)
  • Re: how to practice JDBC programming?
    ... I am reading a book to learn JDBC. ... I do have a Oracle expression version installed in my Window XP. ... Oracle is one of the top database systems out there, and Oracle XE is supposed to be very, very easy to use. ... If I'm not mistaken, a sample schema is also installed, (maybe it's an install-option), and for practicing purposes, like jdbc training, it'd be very convenient. ...
    (comp.lang.java.programmer)
  • DBConvert for Oracle and MySQL 1.0.0
    ... performs two-way conversion from Oracle databases to MySQL server ... database migration to another MySQL database and is quite adept at ... possible conversion errors, etc. ...
    (comp.software.shareware.announce)
  • Problem with SQLLoader Date columns and JDBC access
    ... I'm importing a text file using SQLLoader into an Oracle 9i database. ... But when I try to access this column via JDBC using getTimestampthe driver throws an IllegalArgumentException ) ... I tried the JDBC driver for Oracle9, 10gR1 and 10gR2, no difference. ...
    (comp.databases.oracle.misc)