Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Find-method with dates  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hellow ,
I want to create a find-method that should represent following statement :
select * from emp where date > to_date( '24/01/2002', 'dd/MM/yyyy' );

I defined in my EJB-home-method something like this ...
public Collection findByStukEname( String date ) throws RemoteException, FinderException;

Then I deployed to a J2ee-server ...
and in the orion-ejb-jar.xml I changed the finder-method into ...

<finder-method query="select * from emp where date > to_date( $1 , 'dd/MM/yyyy' )" partial="false">

But i doesn't work ? Did I make a mistake ?? Is there a beter way to do it ?? ( maybe working with java.util.Date ?? )

Karl Laird
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual problem here is where the representation of the string is not exactly matching the internal representation of the database. For example if you query using '24/12/79' to a SQL server database it will not usually manage to find anything. Also the situation is often confused further where both Java and many databases alter the displayed format from the internal format according to the machine locale. I have usually found that using java.sql.Timestamp is the best way to circumvent these problems.
Also try debugging your statement in the database itself - ie enter the sql statement directly into the database query manager / command line / etc and see if it returns what you want. If not then you know the problem isnt in the date conversion but rather with the statement or format. (also dont forget some databases require dates to be surrounded by '#' or other symbols rather than a ' for string ;-)
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!