You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Matthew Forder <fo...@ams.neth.seagate.com> on 2001/09/05 08:43:40 UTC
Criteria - select between 2 dates
I'm trying to build a query where records are selected when a column
containing a date falls between 2 user supplied dates. The code I'm
using looks something like this (the names have been changed to protect
the innocent):
Criteria criteria = new Criteria();
Vector victor = new Vector();
Criteria.Criterion a = criteria.getNewCriterion(SomePeer.CREATED_DATE,
new GregorianCalendar(fyy, fmm, fdd), Criteria.GREATER_EQUAL);
Criteria.Criterion b = criteria.getNewCriterion(SomePeer.CREATED_DATE,
new GregorianCalendar(tyy, tmm, tdd), Criteria.LESS_EQUAL);
criteria.add(a.and(b));
victor = SomePeer.doSelect(criteria);
However, when I try to execute the query, the SQL that is being
generated contains (what looks like) a serialized copy of the
GregorianCalendar objects, rather than something that looks like a date.
Reading from the Turbine API and looking at the source code for
org.apache.turbine.util.db.Criteria I think I'm taking the right
approach, but of course on the other hand I'm probably doing something
dumb.
Any help on this one is appreciated!!
Thanks and regards,
Matt
--
____ | Matthew J. Forder | Data Center Supervisor
/ / () | Seagate Techology | Tel:+31 20 316 7468
\ \ \ | Koolhovenlaan 1 | Fax:+31 20 653 5537
()_/_/ | 1119 NB Schiphol-Rijk, NL | matthew.forder@seagate.com
Re: Criteria - select between 2 dates
Posted by Leon Messerschmidt <le...@opticode.co.za>.
Hi Matt,
That is because the queries of BasePeer is not prepared statements at this
stage. I added some experimental code that does in fact use prepared
statements. You can just replace all the BasePeer.doSelect() with
BasePeer.doPSelect() in your generated Base*Peer classes. I admit it is not
the best way to go, but that is all I have at the moment.
~ Leon
----- Original Message -----
From: "Matthew Forder" <fo...@ams.neth.seagate.com>
To: <tu...@jakarta.apache.org>
Sent: Wednesday, September 05, 2001 8:43 AM
Subject: Criteria - select between 2 dates
> I'm trying to build a query where records are selected when a column
> containing a date falls between 2 user supplied dates. The code I'm
> using looks something like this (the names have been changed to protect
> the innocent):
>
> Criteria criteria = new Criteria();
> Vector victor = new Vector();
> Criteria.Criterion a = criteria.getNewCriterion(SomePeer.CREATED_DATE,
> new GregorianCalendar(fyy, fmm, fdd), Criteria.GREATER_EQUAL);
> Criteria.Criterion b = criteria.getNewCriterion(SomePeer.CREATED_DATE,
> new GregorianCalendar(tyy, tmm, tdd), Criteria.LESS_EQUAL);
> criteria.add(a.and(b));
> victor = SomePeer.doSelect(criteria);
>
> However, when I try to execute the query, the SQL that is being
> generated contains (what looks like) a serialized copy of the
> GregorianCalendar objects, rather than something that looks like a date.
>
> Reading from the Turbine API and looking at the source code for
> org.apache.turbine.util.db.Criteria I think I'm taking the right
> approach, but of course on the other hand I'm probably doing something
> dumb.
>
> Any help on this one is appreciated!!
>
> Thanks and regards,
>
> Matt
>
> --
> ____ | Matthew J. Forder | Data Center Supervisor
> / / () | Seagate Techology | Tel:+31 20 316 7468
> \ \ \ | Koolhovenlaan 1 | Fax:+31 20 653 5537
> ()_/_/ | 1119 NB Schiphol-Rijk, NL | matthew.forder@seagate.com
----------------------------------------------------------------------------
----
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org