开发者

Java persistence date query

开发者 https://www.devze.com 2023-03-25 18:32 出处:网络
I have.... string qString = \"select e from table where id= :id and trunc(Date) = TO_Date(\'03/04/2010\',\'MM/DD/YYYY\')

I have....

string qString = "select e from table where id= :id and trunc(Date) = TO_Date('03/04/2010','MM/DD/YYYY')

Query newQuery = entityManager.createNamedQ开发者_运维百科uery(qstring)
newQuery.setParameter("id",id);

How do I set the date part rather than hard coding it?

I have tried newQuery.setParameter("date",date,TemporalType.Date) but it hasn't worked for me. Any pointers? I have also tried to use just 'newQuery.setParameter("date",date)' and used date as an argument ending me with...

string qString = "select e from table where id= :id and trunc(Date) = :date

, but I believe they aren't formatted correctly, what is the correct way to do this?

*UPDATE*** I am trying to do it with SQL date. Will keep you posted!!!


What is wrong with storing them in Strings just like you do the query??

String date = '03/04/2010';
String dateFormat = 'MM/DD/YYYY';

String qString = "SELECT e FROM table WHERE id = :id 
AND trunc(DATE) = TO_Date(date,dateFormat)";
0

精彩评论

暂无评论...
验证码 换一张
取 消