views:

200

answers:

2

I'm running the java cocoon 2 and castor oql. I'm trying to filter my oql query by today's date, but I can't seem to figure out (or find in google) the syntax of the date. The database is mySql, but the oql is mapped by the java classes... so doing a search on field_date >= Now() doesn't work. Any ideas? I really can't stand the limitations of this site, but it's what i have to work with.

+1  A: 

It's been a while since I used Cocoon, so I can't say I really have a great answer for you. But since this question has been stagnating, a couple of points to suggest;-)

  1. Syntax should only matter if you are coding the literal SQL string. I was under the impression that with castor you can bind the variables (and let OQL select the appropriate format). i.e. " where field_date >= ?", myDateVal

  2. The CastorTransformer seemed to only make brief appearance in one specific version of Cocoon, and AFAIK its not in the latest. If you have control over the Cocoon version you are running, you might want to look at upgrading and alternatives to the CastorTransformer

tardate
+1  A: 

Adapted from the Castor JDO FAQ, assuming that you are comparing against a date and not a timestamp (see OQL reference).

OQLQuery query = db.getOQLQuery("SELECT p FROM Person p "
      +"WHERE lastvisitdate=$2");
query.bind( new Date() ); //new Date() defaults to today.
Alex B