Java NullPointerException when traversing a non-null recordset

Posted by Tim on Stack Overflow See other posts from Stack Overflow or by Tim
Published on 2008-12-18T02:48:10Z Indexed on 2010/04/19 14:33 UTC
Read the original article Hit count: 263

Hello again -

I am running a query on Sybase ASE that produces a ResultSet that I then traverse and write the contents out to a file. Sometimes, this will throw a NullPointerException, stating that the ResultSet is null. However, it will do this after printing out one or two records. Other times, with the same exact input, I will receive no errors.

I have been unable to consistently produce this error. The error message is pointing to a line:

output.print(rs.getString(1));

It appears to happen when the query takes a little longer to run, for some reason. The recordset returns thus far have been very small (4 to 7 records). Sometimes I'll have to run the app 3 or 4 times, then the errors will just stop, as though the query was getting "warmed up". I've run the query manually and there doesn't appear to be any performance problems.

Thanks again!

© Stack Overflow or respective owner

Related posts about java

Related posts about jdbc