aspose file tools*
The moose likes Servlets and the fly likes What could be more better approch for this problem?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "What could be more better approch for this problem??" Watch "What could be more better approch for this problem??" New topic
Author

What could be more better approch for this problem??

Mahajan Bhupendra
Ranch Hand

Joined: Dec 01, 2000
Posts: 118
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).]


<B>Bhupendra Mahajan</B>
shilpa kulkarni
Ranch Hand

Joined: Jun 07, 2000
Posts: 87
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

Joined: Oct 08, 2001
Posts: 14
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).]


homeboy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What could be more better approch for this problem??