I am generating a table and inserting the data into that table. The table is created from data that has complex relationships. We created this so users of our BI tool could easily deal with the data.
We have a bunch of these tables that get created each one is different based on the user generated data. In one case we are getting index out of range exception. When inspecting the meta data it is not out of range.
The exact exception message is:
com.microsoft.sqlserver.jdbc.SQLServerException: The index 13 is out of range.
The generated insert statement is:
INSERT INTO [F22_AF] ([frcId],[eId],[aId],[dateCreated],[DateofThing],[Wasthisaninjury],[Whowainjured],[WhowainjuredFNAME],[WhowainjuredLNAME],[Whatwasinvolved],[WhatwasinvolvedDATA],[WhatOptionsWereAvailable],[AccidentWitnessed]) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)
When the value for accident witnessed is set the exception is thrown. When the value is about to be set I printed the column index and the value:
13 : AccidentWitnessed = false
When it fails I printed out the meta data from the insert statement and got this:
parameterMetaData.getParameterCount()=13
ColIndex – Type || Class
1 – int || java.lang.Integer
2 – int || java.lang.Integer
3 – int || java.lang.Integer
4 – datetime || java.sql.Timestamp
5 – datetime || java.sql.Timestamp
6 – nvarchar || java.lang.String
7 – int || java.lang.Integer
8 – nvarchar || java.lang.String
9 – nvarchar || java.lang.String
10 – int || java.lang.Integer
11 – nvarchar || java.lang.String
12 – int || java.lang.Integer
13 – bit || java.lang.Boolean
When I try to set col index 13 I get Index Out Of Range, however according to the meta data it exists! If it didn’t exist I would get another out of range exception.
The same code works for a different set of data.
Can anyone explain why this error would occur when the column index exists?
My advice? Believe the JVM. It doesn’t matter what you think.
You’re not looking at the right spot to understand what’s going wrong. Write a small, self-contained example and run it in a debugger. You’ll be able to see where the code is going awry that way.