my dog learned polymorphism
The moose likes JDBC and Relational Databases and the fly likes Invalid column 1, use next() before calling getXXX() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Invalid column 1, use next() before calling getXXX()" Watch "Invalid column 1, use next() before calling getXXX()" New topic

Invalid column 1, use next() before calling getXXX()

Ricardo Marques

Joined: May 08, 2002
Posts: 27
I have a connection pool and there is a first level tier of clients which accesses the database. This tier returns a ResultSet to be used by objects in a second level tier.
Each element of the second tier, has one static element of the first tier, which is called when an access to the DB is needed. This way I am always reusing the connections to the database.
One of the second level clients, performs several selects, all of them using the first level client which gets its ReusltSet cleaned after every execution, when I call the corresponding method.
However there seems to be some kind of problem. Somewhere in my code I'm doing this:

I get a runtime exception which says I cannot do getLong(1), without doing next() first, but I am doing that. I don't understand this problem. I'm using BEA Weblogic 6.1 with MSSQL Server 2000.
Can anybody help? Thanks.

Sun Certified Programmer for the Java 2 Platform 1.4<p>If I can create, I will make mistakes. If I can learn with them, it must be some kind of art.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

What if no results were returned? You should be checking if there are results before retrieving the value...

not sure if this is the problem though. It's hard to tell, when you separate the connection/statement/resultset from each other. The code to the connection may affect your resultset as well as your code to the statements.
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

If their were no results he would get a different exception. He has likely just overlooked something. can you be sure of exactly where the exception is being thrown? are you looking at a stack trace?
I agree. Here's the link:
subject: Invalid column 1, use next() before calling getXXX()
It's not a secret anymore!