How to query a Date Column in SQL

From: Laura P (laura.paterson_at_gmail.com)
Date: 08/18/04


Date: 18 Aug 2004 09:34:17 -0700

Hi,

I'm sorry if this is a very noddy question, but I seem to have a block
on how to do this...

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!

Many thanks,

Laura



Relevant Pages

  • Re: dbdebunk Quote of Week comment
    ... > a lot of really bad SQL programmers. ... But SQL does not have a pointer data type or the ... > being told to design a database. ... But why is little Cindy Lou Who employee ...
    (comp.databases.theory)
  • Re: DBMS and lisp, etc.
    ... Naively implemented with SQL, again for 10 ... (1 query for the initial orders, 1 query for each order for its ... soon as you upgrade to the SQL database. ... (eq (order-customer orderA) ...
    (comp.lang.lisp)
  • Re: dbdebunk Quote of Week comment
    ... > a lot of really bad SQL programmers. ... a surrogate key should support the primary key. ... But SQL does not have a pointer data type or the ... > being told to design a database. ...
    (comp.databases.theory)
  • Re: dbdebunk Quote of Week comment
    ... But SQL does not have a pointer data type or the ... More and more programmers who have absolutely no database training are ... But why is little Cindy Lou Who employee ...
    (comp.databases.theory)
  • Re: Just say no to threads [Was: Software architecture]
    ... they knew there was going to be a database in the app. ... Now my colleague just spent a couple/three weeks designing an SQL ... Turns out they have a flat file of sample information, ...
    (comp.object)