aspose file tools
The moose likes Beginning Java and the fly likes date and query Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "date and query" Watch "date and query" New topic
Author

date and query

mark smith
Ranch Hand

Joined: Apr 05, 2005
Posts: 240
hi

i have problem to use a date in a query



i get the error:



any idea?
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 679

Hi.

I think that that the problem is in your select statement. If the datePub field of the database table is a string then your date should be withing single quotes.

-- Kaydell
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12929
    
    3

This is not a Java problem - it's an SQL problem. Your SQL statement:

select * from test where datePub >= 2005-10-01

is not a valid SQL statement. The best way to do queries or updates with parameters in Java is by using PreparedStatement, like this:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: date and query
 
Similar Threads
Difference in GMT Time and Server Time
Date and month by by default
Passing java.sql.date to constructors
Converting Timestamp to date, month, year
Problem with adding months to Gregorian Calender