Blogger

Delete comment from: Java67

Anonymous said...

I had spent 3 days to find the root cause of "com.microsoft.sqlserver.jdbc.SQLServerException: The index 46 is out of range" in one of Java application which uses SQL Server stored procedure to insert and update data. I checked that number of placeholder was equal to number of setString() or setXXX() call we are making, but still we are getting the same error. After much investigation and by luck I found that the stored procedure had 46 parameters but we are only setting 45 parameters from Java side because the last one was always populated by stored procedure. When I added two new parameters, I added them after this last parameter which are set in stored procedure, this caused the problem because now Java layer need to set parameter at 46th index but there was only 45 placeholder. This is quite weird to be honest, but if you face the issue to check stored proc as well. The issue resolved by changing the order of parameters in stored proc e.g. adding two new paramters before this last parameter which is set by default in stored procedure. This way, number of placeholder, number of setXXX() call and parameter index in stored proc all matched.

Oct 7, 2016, 2:07:48 AM


Posted to How to Fix SQLServerException: The index is out of range? JDBC Example

Google apps
Main menu