File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Invalid column 1, use next() before calling getXXX()" Watch "Invalid column 1, use next() before calling getXXX()" New topic
Author

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

Ricardo Marques
Greenhorn

Joined: May 08, 2002
Posts: 27
Hi.
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.
Jamie
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?
 
 
subject: Invalid column 1, use next() before calling getXXX()