Sunday, January 07, 2007

SQLException on ResultSet.absolute()

This one came up at a time when I least expected it. I had an SP which I had to execute to get the results. I was using SQL Server 2K. I wrote the code to execute the SP, iterated through the ResultSet and get the data.

Execution: java.sql.SQLException: Result set type is TYPE_FORWARD_ONLY

Got confused. Tried tinkering around for a while. Nothing. Then thought probably the server has gone bonkers. Changed my code to

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);

Still nothing. Posted on Sun Java forums. Someone suggested it could be an issue with the driver. Realized that the only way to test would be changing the driver. Changed it to JTDS from SourceForge. Same error. Hey!!!

Did a Google with the error message. It cropped up this link. It turned out that any SP in SQL Server with more than one SELECT or a SELECT with SET/PRINT degrades the resultset type. Modified my SP and it works now.

No comments: