This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Not Quite sure how there is a SQLException on this line... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Not Quite sure how there is a SQLException on this line..." Watch "Not Quite sure how there is a SQLException on this line..." New topic
Author

Not Quite sure how there is a SQLException on this line...

Michael Paul
Greenhorn

Joined: Mar 29, 2008
Posts: 14
Hi,

I am trying to just get the value of a column in a DB that stores an int. The value is not null. I have tried both using a column name and index number and with both I get a SQLException error. This is the code:



The line I am getting the error on is:




Anyone have an idea as to why this would be happening? All help would be appreciated.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

Michael,
JDBC requires you call rs.next() before rs.getXXX(). A typical idiom is:


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

Note that we have a forum just for JDBC questions up near the top of the forum list. I'll move this for you.
Michael Paul
Greenhorn

Joined: Mar 29, 2008
Posts: 14
Thank you very much, sometimes I shock myself with how I overlook small things! I new that you had to do rs.next() and for some reason refused to think of that...Thank you very much for your help!

Michael
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not Quite sure how there is a SQLException on this line...
 
Similar Threads
Retrieve a column value from ArrayList
JDBC: What is the concrete class that implements the jdbc interfaces
running the result from the end
Tryin' to create a small MS SQL Java Application
Exception in thread "main"