• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to Retrieve data from t he databse using CriteriaQuery

Vidya Gupta
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi All,

I am trying to fetch data from the database.

My table contains the following 5 columns,

S.No Roll_No Name Branch Subject Marks
1 001 aaa mpc Math 85
2 001 bbb mpc Chem 90
3 001 ccc mpc Phy 89

I am trying to get the Name ,Branch,Marks data based on Roll_No column.

Here i want the output like this in a java list,

Name Branch Subject Marks
aaa mpc Math 85
bbb mpc Chem 90
ccc mpc Phy 89

My code looks like this,

@SuppressWarnings({ "rawtypes", "unchecked" })
private List<MyClassName> getData(int rNo) throws Exception {

System.out.println("getting data " + rNo);

EntityManager EM = getEntityManager();

try {
EM .clear();

CriteriaBuilder cb = EM.getCriteriaBuilder();

CriteriaQuery<MyClassName> cq = cb.createQuery(MyClassName.class);
Root metricRoot = cq.from(MyClassName.class);

if (rNo!= null) {
return EM.createQuery(cq).getResultList();
} else {
return EM.createQuery(cq).getResultList();
} catch (Exception ex) {
logger.error("Exception : "
+ ex.getMessage());
throw ex;
} finally {

In the above class, MyClassName is a View in database.

When i run the above code am getting some parsing exceptions. I am unable to understand that exactly. Can any one please suggest me.

Thanks in Advance,
Vidya Gupta
Aayushya Devmurari
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please post the stack trace ??
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!