-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: MySQL, DateTime and between query
PostPosted: Fri Oct 26, 2007 4:02 pm 
Newbie

Joined: Sat Oct 28, 2006 3:05 pm
Posts: 10
Hello. I have the following problem: when I run the query manually through the command line client:
Code:
select * from book where printed between '2007-10-26 20:12:00' and '2007-10-26 22:12:00'

it works fine, returs one record (as it should).

However, when I use the code:
Code:
Query q = session.createQuery("from  Book b where b.printed between :start and :end");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
q.setDate("start", df.parse("2007-10-26 20:12:00"));
q.setDate("end", df.parse("2007-10-26 22:12:00"));
Book book = (Book) q.uniqueResult();

it doesn't.
When I set log level to debug, I can see that Hibernate translates the date parameters according to my locale or something (it outputs:
binding '26 październik 2007' to parameter: 1
binding '26 październik 2007' to parameter: 2
(polish computer)
First, this is different from simple Date.toString() (anyway, toString wouldn't work either), and why doesn't it output the time part?

When I do this:
Code:
q.setString("start", df.parse("2007-10-26 20:12:00"));
q.setString("end", df.parse("2007-10-26 22:12:00"));

the result is again one row. This means the string parameters worked.

But I would like to use java.util.Date / setDate() method. So please could anyone tell me what is the right way to deal with that?
And the another thing is - mysql has only one format for the datetime type (I suppose?). I'm not sure, but what if oracle has many, and it defaults to the server locale, but could be set to something completely customized? Is this true? How can this be dealt with?
Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 29, 2007 2:37 pm 
Newbie

Joined: Sat Oct 28, 2006 3:05 pm
Posts: 10
Noone will halp me?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.