my dog learned polymorphism
The moose likes Java in General and the fly likes Comparing oracle date with java util Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Comparing oracle date with java util " Watch "Comparing oracle date with java util " New topic

Comparing oracle date with java util

Kenneth Tian

Joined: Nov 30, 2004
Posts: 1
I am currently doing a little web-based project of my own and have some trouble comparing a with an oracle Date field. It gives the error that SQL command is not properly ended when I try to do so:

java.util.Date newDate=new java.util.Date();
ResultSet rset = stmt.executeQuery ("SELECT DISTINCT issue_dt FROM passcard WHERE passcard.expire_dt>"+newDate);

Have tried formatting it with:
SimpleDateFormat sdf=new SimpleDateFormat("d-MMM-yy");
as the db format is 7-MAY-04,
but that doesn't seem to work as yy is recognised as an illegal character in the database.Thanks in advance and would be grateful for any help given
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Try using java.sql.Date with a PreparedStatement instead.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
It sounds like a problem with SQL syntax rather than anything to do with Java directly. You might want to try adding a semi-colon to the end of your SQL query:

Also, you may need to use SimpleDateFormat.format() in order to actually format the date into a String in the correct format for your database.

Keep Coding!


p.s. We have a database forum here at the Saloon where such questions are more appropriate. In fact, the people there probably will be able to answer your questions a lot better than I can.
[ November 30, 2004: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Comparing oracle date with java util
It's not a secret anymore!