How do I retrieve the raw SQL for a Query object (or criteria)?
The SQL I am using now (working correctly):
SimpleDateFormat fmt = (SimpleDateFormat) DateFormat.getDateTimeInstance();
fmt.applyPattern("yyyy-MM-dd HH:mm:ss");criteria.addSql("StartDate >= '" + fmt.format(startDate) + "' AND StartDate < '" +
fmt.format(endDate) + "'");
Query query = QueryFactory.newQuery(Event.class, criteria);
Notice that I'm using the addSql() method... I cannot get the addLessThan to work with identical date values.
Thanks, Aaron
Jakob Braeuchi wrote:
hi aaron,
afaik ojb does nothing special when using dates with mysql, it maybe the driver.
could you please post the sql that caused the problem, so i can check it with my mySQL db.
hth jakob
Aaron Longwell wrote:
Edson,
I think there's something wrong with the way OJB is turning an addLessThan to SQL code on the mySQL implementation. I switched my code to SimpleDateFormat the submitted dates and turn them into mySQL-DateTime format (2003-05-18 00:00:00). I then use addSQL("StartDate <= '" + strStartDate + "' AND StartDate < '" + strEndDate + "'");
This works just fine... I guess I can deal with it for now.
Edson Carlos Ericksson Richter wrote:
Nop. I'm using SapDB and MS SQL. Maybe you are having some kind of driver issue here.
Edson Richter
----- Original Message ----- From: "Aaron Longwell" <[EMAIL PROTECTED]>
To: "OJB Users List" <[EMAIL PROTECTED]>
Sent: Monday, June 16, 2003 10:40 AM
Subject: Re: addLessThan or addBetween with Dates in mySQL
Edison,
I'm actually using the same conversion... were you using mySQL?
Thanks, Aaron
Edson Carlos Ericksson Richter wrote:
Hi!
I've used Dates normally with less than, greater than and between with SapDB. Unique thing I had todo is put a "conversion" in field like:
conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlTimes
t
ampFieldConversion"
then it works for me.
Edson Richter
----- Original Message ----- From: "Aaron Longwell" <[EMAIL PROTECTED]>
To: "OJB User" <[EMAIL PROTECTED]>
Sent: Monday, June 16, 2003 2:42 AM
Subject: addLessThan or addBetween with Dates in mySQL
OJB Experts,
I am using mySQL with OJB to build an event calendar. I need to display
1 month's worth of events. At first, I tried code like this:
criteria.addBetween("EventDate", startDate, endDate);
where startDate and endDate are java.util.Dates. I got no results, even
though there are events in the database between those two dates. I
retried with a single addGreaterOrEqualThan(). This worked as expected,
returning events whose date was on or after the startDate submitted. I
then tried the addLessOrEqualThan(). This returned 0 results, even
though there are events before the submitted date in the database.
The Javadocs show examples of these commands being used with integers
and not dates. Am I wrong to even attempt this? I would prefer not to
implement my method an addSQL() call. I would think Date-handling would
be automatic with an OJB tool.
Thanks for the help, Aaron
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.489 / Virus Database: 288 - Release Date: 10/6/2003
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.489 / Virus Database: 288 - Release Date: 10/6/2003
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
