You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Raoul Markus <ra...@t-online.de> on 2003/09/01 20:47:37 UTC

newbie q: Criteria for java.util.Date

Hi,

I tried the following code, but this query didn't return any hits:

public static Collection getSessionsOfDay(DBConnector pDbconnector,Date 
pDateHeld, String pUser) {
...
		tCrit.addEqualTo("DATE_HELD", pDateHeld);
...
		Query tQuery = new QueryByCriteria(SDBSession.class, tCrit);
}





and I had to replace it by the following (which works, but is no good):


public static Collection getSessionsOfDay(DBConnector pDbconnector,Date 
pDateHeld, String pUser) {
...
		// TODO: this date operations  are not nice...
		Calendar tCal = Calendar.getInstance();
		tCal.setTime(pDateHeld);
		// make a string like "2003-8-29", which is recognized by mysql
		String tDateStr = "" + tCal.get(Calendar.YEAR) + "-" + 
(1+tCal.get(Calendar.MONTH)) + "-" + tCal.get(Calendar.DAY_OF_MONTH);  
		tCrit.addEqualTo("DATE_HELD", tDateStr);
...
		Query tQuery = new QueryByCriteria(SDBSession.class, tCrit);


in mysql (3.23.55-log), the column is defined as DATE and holds to my opinion 
only the day (not the time). the java.util.Date of course has the exact time, 
maybe this causes the null result?

But with the tDateStr I am no longer independend of the db (i.e. which date 
strings it recognizes). 

any tips, thoughts?

Thanks in advance.

-- 
Raoul Markus
PGP key available from servers


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


Re: newbie q: Criteria for java.util.Date

Posted by Edson Carlos Ericksson Richter <ed...@mgrinformatica.com.br>.
Have you tried to use 

org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlTimestampFieldConversion

as conversion in XML?

Works for me like a charm.

Best regards,

Edson Richter


----- Original Message ----- 
  From: Raoul Markus 
  To: OJB Users List 
  Sent: Monday, September 01, 2003 3:47 PM
  Subject: newbie q: Criteria for java.util.Date


  Hi,

  I tried the following code, but this query didn't return any hits:

  public static Collection getSessionsOfDay(DBConnector pDbconnector,Date 
  pDateHeld, String pUser) {
  ...
  tCrit.addEqualTo("DATE_HELD", pDateHeld);
  ...
  Query tQuery = new QueryByCriteria(SDBSession.class, tCrit);
  }





  and I had to replace it by the following (which works, but is no good):


  public static Collection getSessionsOfDay(DBConnector pDbconnector,Date 
  pDateHeld, String pUser) {
  ...
  // TODO: this date operations  are not nice...
  Calendar tCal = Calendar.getInstance();
  tCal.setTime(pDateHeld);
  // make a string like "2003-8-29", which is recognized by mysql
  String tDateStr = "" + tCal.get(Calendar.YEAR) + "-" + 
  (1+tCal.get(Calendar.MONTH)) + "-" + tCal.get(Calendar.DAY_OF_MONTH);  
  tCrit.addEqualTo("DATE_HELD", tDateStr);
  ...
  Query tQuery = new QueryByCriteria(SDBSession.class, tCrit);


  in mysql (3.23.55-log), the column is defined as DATE and holds to my opinion 
  only the day (not the time). the java.util.Date of course has the exact time, 
  maybe this causes the null result?

  But with the tDateStr I am no longer independend of the db (i.e. which date 
  strings it recognizes). 

  any tips, thoughts?

  Thanks in advance.

  -- 
  Raoul Markus
  PGP key available from servers


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



  ---
  Outgoing mail is certified Virus Free.
  Checked by AVG anti-virus system (http://www.grisoft.com).
  Version: 6.0.514 / Virus Database: 312 - Release Date: 28/8/2003

Re: newbie q: Criteria for java.util.Date

Posted by "Daniel R. Ambrosio" <jo...@uol.com.br>.
Hi Raoul,

Did u try to use java.sql.Date instead of java.util.Date??
I think this might solve your problem!!

Cheers,
Daniel

Raoul Markus wrote:

>Hi,
>
>I tried the following code, but this query didn't return any hits:
>
>public static Collection getSessionsOfDay(DBConnector pDbconnector,Date 
>pDateHeld, String pUser) {
>...
>		tCrit.addEqualTo("DATE_HELD", pDateHeld);
>...
>		Query tQuery = new QueryByCriteria(SDBSession.class, tCrit);
>}
>
>
>
>
>
>and I had to replace it by the following (which works, but is no good):
>
>
>public static Collection getSessionsOfDay(DBConnector pDbconnector,Date 
>pDateHeld, String pUser) {
>...
>		// TODO: this date operations  are not nice...
>		Calendar tCal = Calendar.getInstance();
>		tCal.setTime(pDateHeld);
>		// make a string like "2003-8-29", which is recognized by mysql
>		String tDateStr = "" + tCal.get(Calendar.YEAR) + "-" + 
>(1+tCal.get(Calendar.MONTH)) + "-" + tCal.get(Calendar.DAY_OF_MONTH);  
>		tCrit.addEqualTo("DATE_HELD", tDateStr);
>...
>		Query tQuery = new QueryByCriteria(SDBSession.class, tCrit);
>
>
>in mysql (3.23.55-log), the column is defined as DATE and holds to my opinion 
>only the day (not the time). the java.util.Date of course has the exact time, 
>maybe this causes the null result?
>
>But with the tDateStr I am no longer independend of the db (i.e. which date 
>strings it recognizes). 
>
>any tips, thoughts?
>
>Thanks in advance.
>
>  
>



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


Re: newbie q: Criteria for java.util.Date

Posted by LAURENT Stephane <sl...@adequates.com>.
Hi,
have a look on SimpleDateFormat (use YYY-M-d).
  ----- Original Message ----- 
  From: Raoul Markus 
  To: OJB Users List 
  Sent: Monday, September 01, 2003 8:47 PM
  Subject: newbie q: Criteria for java.util.Date


  Hi,

  I tried the following code, but this query didn't return any hits:

  public static Collection getSessionsOfDay(DBConnector pDbconnector,Date 
  pDateHeld, String pUser) {
  ...
  tCrit.addEqualTo("DATE_HELD", pDateHeld);
  ...
  Query tQuery = new QueryByCriteria(SDBSession.class, tCrit);
  }





  and I had to replace it by the following (which works, but is no good):


  public static Collection getSessionsOfDay(DBConnector pDbconnector,Date 
  pDateHeld, String pUser) {
  ...
  // TODO: this date operations  are not nice...
  Calendar tCal = Calendar.getInstance();
  tCal.setTime(pDateHeld);
  // make a string like "2003-8-29", which is recognized by mysql
  String tDateStr = "" + tCal.get(Calendar.YEAR) + "-" + 
  (1+tCal.get(Calendar.MONTH)) + "-" + tCal.get(Calendar.DAY_OF_MONTH);  
  tCrit.addEqualTo("DATE_HELD", tDateStr);
  ...
  Query tQuery = new QueryByCriteria(SDBSession.class, tCrit);


  in mysql (3.23.55-log), the column is defined as DATE and holds to my opinion 
  only the day (not the time). the java.util.Date of course has the exact time, 
  maybe this causes the null result?

  But with the tDateStr I am no longer independend of the db (i.e. which date 
  strings it recognizes). 

  any tips, thoughts?

  Thanks in advance.

  -- 
  Raoul Markus
  PGP key available from servers


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



  ---
  Outgoing mail is certified Virus Free.
  Checked by AVG anti-virus system (http://www.grisoft.com).
  Version: 6.0.514 / Virus Database: 312 - Release Date: 29/08/2003