aspose file tools*
The moose likes JDBC and the fly likes problem with getObject() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem with getObject()" Watch "problem with getObject()" New topic
Author

problem with getObject()

Mahajan Bhupendra
Ranch Hand

Joined: Dec 01, 2000
Posts: 118
Hi,
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??
Thanks in advance..
Bhupendra


<B>Bhupendra Mahajan</B>
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
I think the problem is that you are trying to access the same column twice. You are calling getObject() twice. You can retrieve the data the first time, and then use the wasNull() emthod to check if the columns read was null. Check the API for the wasNull() method.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Mahajan Bhupendra
Ranch Hand

Joined: Dec 01, 2000
Posts: 118
Yes Bosun,
u r right i converted the code like this..
Object ob=row.getObject("question_no");
if(ob!=null)
questionNo=((Integer)ob).intValue();
but don't u think i m wasting one object???
BTW Thanx
Bhupendra
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

why do you not want to use the getInt() method? maybe we can help you use a cleaner methodology for attaining your goal(and maybe not!). It just seems like there is a whole lot of stuff going on, when a method (getInt()) already exists.
my suggestion is:

Read the docs about ResultSet.wasNull() method to see if it can achieve the same goal
Jamie

[This message has been edited by Jamie Robertson (edited October 11, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with getObject()