db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From econroy <econ...@ECONROY.NET>
Subject Re: how to write a query with Date type
Date Wed, 09 Nov 2005 18:56:04 GMT
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
>
>
>Thanks in advance.
>
>Jill
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>For additional commands, e-mail: torque-user-help@db.apache.org
>
>
>
>  
>
Using Criteria and calender can solve this problem.
This is sort of the type of code you would use:
GregorianCalendar calendar = new GregorianCalendar();
//  this  normalizies  the dates
calendar.setTime(startDate);
calendar.setTime(endDate);
Criteria sql = new Criteria();
sql.add(aDate, startDate, Criteria.GREATER_EQUAL);
Criteria.Criterion criterion = sql.getCriterion(aDate);
criterion.and(sql.getNewCriterion(criterion.getTable(), 
criterion.getColumn(), endDate, Criteria.LESS_EQUAL));
try
{
List list = aTablePeer.doSelect(sql);
}
catch(Exceptiion e)
{}


---------------------------------------------------------------------
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