Monday, April 6, 2009

Descriptor index not valid

"java.sql.SQLException: Descriptor index not valid."


If you are running an SQL query (in this case with Java) against an AS/400 and get the above message, try replacing the code in your resultset loop. Find the line that looks like this:
rs.getString(0)
And replace with lines like this:

rs.getString("PFNMCN");

Notice, the records is being retrieved by name instead of by index. Alternately, you can try:

rs.getString(1);


The underlying problem is resultset indexes start at [1] instead of [0]. This is confusing as most Java indexes start counting at 0. Hope this helps. What the message should probably say is "resultset index is out of bounds for the returned set". But jt400 is a free driver, so we can live with that message. :)

Also note, that if you do "SELECT PFNMCN AS FIRSTNAME...", then your code should read:

rs.getString("FIRSTNAME");

This java error message can be confusing at first, but it is a very quick fix!

Edit: If you use an exit point program for security purposes, make sure to capitalize your "SELECT" statements!!!!

-Tres

2 comments:

Brady said...

Thanks Larry, that helped me out this morning. DB2 error messages are not always clear as glass.

Tres Finocchiaro said...

Glad it helped you! We spent hours before figuring that one out!!!