db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "jill han" <j...@bynum.com>
Subject RE: how to write a query with Date type
Date Wed, 09 Nov 2005 18:21:47 GMT
Thanks.
I formatted java.util.Date object to java.sql.Date format. It worked
fine.

I could use Criteria date stuff, but torque 3.1 Criteria could not
process a query like
Criteria.addSelectColumn("COUNT(Unique("+aTablePeer.aColumn + "))")
Or 
Criteria.addSelectColumn("Round(Avg(" + aTablePeer.aColumn + "), 2)")

-----Original Message-----
From: Dave Newton [mailto:newton@pingsite.com] 
Sent: Wednesday, November 09, 2005 10:22 AM
To: Apache Torque Users List
Subject: Re: how to write a query with Date type

jill han wrote:

>Below is a piece of code to get records from a table and exception
>// startDate and endDate are Date object
>// aDate has Date data type in oracle db
>String sql = "Select * from aTable ";
>sql = sql + " Where aDate ";
>sql = sql + " Between '" + startDate + "' And '" + endDate + "' ";
>List sqlResult = aTablePeer.executeQuery(sql);
>
>org.apache.torque.TorqueException: ORA-01858: a non-numeric character
>was found where a numeric was expected
>  
>
I'm assuming you're asking why this didn't work.

java.util.Date's toString returns something along the following lines:

Wed Nov 09 11:19:05 GMT-05:00 2005

which isn't what an SQL date looks like (although I don't deal with 
Oracle much, so I could be completely wrong).

You'll want to convert it to a format that Oracle understands.

I thought the Criteria date stuff would do that work for you (I don't 
know that either, though ) If that's true, is there a reason to avoid 
Criteria for this usecase?

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message