EJB QL - selecting current year in date type

Hi Experts,

I am working on jboss seam web app and I need to modifiy ejb ql so that I can use same code next year without modifying code.

select qualReport from QualReport qualReport where qualReport.countyName='cherokee' order by qualReport.quarter, qualReport.rowOrder

The above works fine, but I want to select rows only for current year. There is a createdDate column that stores oracle Date when rows were inserted and there are some rows that were created this year.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This is going to be dependent on what format dates are stored in oracle. On mySQL, I was able to get this to return rows for the current year only. Note that within mySQl dates are stored in the format "2010-02-17 16:15:20"

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar calObj = new GregorianCalendar(new GregorianCalendar().get(Calendar.YEAR), Calendar.JANUARY, 1);
logger.debug("The calender corresponding to first of the year is: " + format.format(calObj.getTime()));
criteria = em
                                    .createQuery("SELECT billingDetails FROM CreditCard as billingDetails where billingDetails.created > '" + format.format(calObj.getTime()) + "'");
Sathish David Kumar NArchitectCommented:
you can user Year(GetDate()) in the query then you will get the year of the date
Sathish David Kumar NArchitectCommented:

"SELECT billingDetails FROM CreditCard as billingDetails where billingDetails.created > Year(GetDate())"
With oracle it would be something like this

"SELECT billingDetails FROM CreditCard as billingDetails where billingDetails.created > TRUNC(SYSDATE, 'YEAR')"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.