• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparing oracle date with java util

 
Kenneth Tian
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am currently doing a little web-based project of my own and have some trouble comparing a java.util.date 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
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using java.sql.Date with a PreparedStatement instead.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Layne

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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic