• Post Reply Bookmark Topic Watch Topic
  • New Topic

date and query  RSS feed

 
mark smith
Ranch Hand
Posts: 258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i have problem to use a date in a query



i get the error:



any idea?
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!