• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What could be more better approch for this problem??

 
Mahajan Bhupendra
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
in servlet i m using one bean which gets something from
databse.i m using ms access as backend.
i am having a field "question_no" with data type Number
when i am trying to get the value with getObject() method of
ResultSet i am getting SQLException saying that : No Data Found
although i m able to get other data which is in terms of string
i m geeting the data using..
if(row.getObject("question_no")!=null)
questionNo=((Integer)row.getObject("question_no")).intValue();
Since i want to check for null value also i don't eant to
use getInt() method..
What could be wrong??
Surprisingly i found very bad solution for this..
Object o=rs.getObject("answer_correct");
if(o!=null){
int a=((Integer)o).intValue();
System.out.println(a);
}
but i think this is not the correct way of doing this..
could anybody suggest me some better way
Surpisingly on other fields i m using getString() and they are working fine
Thanks in advance..
Bhupendra

[This message has been edited by Mahajan Bhupendra (edited October 11, 2001).]
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In javadocs, i found this under java.sql.ResultSet interface

For maximum portability, ResultSet columns within each row should be read in left-to-right order and each column should be read only once.

In the first block of code you are reading the same column twice, which is wrong. The second is the better approach.
 
Toyin Sogeke
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Try the following:
questionNo = 0;
String strValue = row.getString("question_no");
if (strValue != null && strValue.trim().length() > 0)
{
questionNo = Integer.parseInt( strValue );
}
Cheers
Originally posted by Mahajan Bhupendra:
Hi,
in servlet i m using one bean which gets something from
databse.i m using ms access as backend.
i am having a field "question_no" with data type Number
when i am trying to get the value with getObject() method of
ResultSet i am getting SQLException saying that : No Data Found
although i m able to get other data which is in terms of string
i m geeting the data using..
if(row.getObject("question_no")!=null)
questionNo=((Integer)row.getObject("question_no")).intValue();
Since i want to check for null value also i don't eant to
use getInt() method..
What could be wrong??
Surprisingly i found very bad solution for this..
Object o=rs.getObject("answer_correct");
if(o!=null){
int a=((Integer)o).intValue();
System.out.println(a);
}
but i think this is not the correct way of doing this..
could anybody suggest me some better way
Surpisingly on other fields i m using getString() and they are working fine
Thanks in advance..
Bhupendra
[This message has been edited by Mahajan Bhupendra (edited October 11, 2001).]

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic