Re: How to query a Date Column in SQL
From: kaeli (tiny_one_at_NOSPAM.comcast.net)
Date: 08/18/04
- Previous message: Fredrik Bertilsson: "Re: Java database app. example ?"
- In reply to: Laura P: "How to query a Date Column in SQL"
- Next in thread: Lee Fesperman: "Re: How to query a Date Column in SQL"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 18 Aug 2004 12:29:18 -0500
In article <3a9a26f2.0408180834.3249ff5f@posting.google.com>,
laura.paterson@gmail.com enlightened us with...
>
> 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'm not sure what you're trying to accomplish and what you can't get, but I
do direct queries for my own personal use without prepared statements to set
the date. I still technically prepare a statement, but it just goes straight
through.
Snippet:
String qs=request.getParameter("qs");
...
Statement s = conn.prepareStatement(qs);
ResultSet rs = s.executeQuery();
So, if I want to so something with my date field, I pass a direct query, such
as (oracle syntax)
select * from myTbl where myDateField=to_char('12/21/2004','MM/DD/YYYY')
If you wanted to get a date like that...
String qs;
java.util.Date myDate = new java.util.Date();
SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
qs = "select * from myTbl where myDateField=to_char('"+
df.format(myDate)+
"','MM/DD/YYYY')";
Does that help?
-- -- ~kaeli~ What's another word for thesaurus? http://www.ipwebdesign.net/wildAtHeart http://www.ipwebdesign.net/kaelisSpace
- Previous message: Fredrik Bertilsson: "Re: Java database app. example ?"
- In reply to: Laura P: "How to query a Date Column in SQL"
- Next in thread: Lee Fesperman: "Re: How to query a Date Column in SQL"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]