-->
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: calculating the % of votes
PostPosted: Tue Jan 29, 2008 4:58 pm 
Newbie

Joined: Tue Jan 29, 2008 4:54 pm
Posts: 1
Hi,

I have a results table which has answers n questions sent in by the user.i need to calcute the % of v otes for submissions by user...I have wriiten some thin like this..but it keeps on thrwoing null pointer..can ne1 suggest somethhing or better way for doing this.
Session session = null;
Query query = session.createQuery("select count(*) from poll_results where asnwer_id like '%'");
int count = ((Number) query.list()).intValue();

Query query1 = session.createQuery("select count(*) from poll_results where question_id like '%");
int count1 = ((Number) query.list()).intValue();

int result = (count/count1)*100;

return result;


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 11:55 pm 
Newbie

Joined: Wed Sep 19, 2007 11:30 pm
Posts: 12
Location: indonesia
Code:
Session session = null;
// -> the session is null here.. that's why it throw null pointer exception
// -> you should create a session with SessionFactory
Query query = session.createQuery("select count(*) from poll_results where asnwer_id like '%'");
//you should do this instead:
//int count = ((Number)query.list().get(0).intValue();
int count = ((Number) query.list()).intValue();

Query query1 = session.createQuery("select count(*) from poll_results where question_id like '%");
//int count1 = ((Number)query.list().get(0)).intValue();
int count1 = ((Number) query.list()).intValue();

int result = (count/count1)*100;

return result;

_________________
An incredible programmer is worthier than a common programmer because of his/her ideas, not his/her codes.


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.