Strange Obi-Wan Error

I was doing some JDBC today and I forgot that column indexes are 1-based instead of 0-based. It took me a while to figure out what was wrong since the exception message I kept getting was

java.sql.SQLException: Column Index out of range, 0 > 11.

Despite the fact that zero is not, in fact, greater than 11, I checked to make sure I had used < and not <= in my loop because I thought I was going beyond the maximum index… but I wasn’t. The problem was that I wasn’t even getting to the first index! Then I remembered that I started my loop at 0 and that JDBC ResultSets start indexing at 1. Changing it to 1 fixed the problem, but the error message is wrong. It should have told me that 0 was less than 1 or, more helpfully, that ResultSet indexes start at 1…

Advertisements