2

I have been working with a snippet of code where java.sql.SQLException: Invalid column index is being thrown at runtime.

I have worked several times in past with this exception and every time i find that developer has used wrong indexes while using rs.getsString() method.

But my problem this time is that i am getting this exception while inserting the records into the table. Can any one please suggest what is the reason why i am getting this exception while inserting into the database?

Also i am not able to see the query being executed at the time of exception because the driver being used (oracle drivers) don't print the query when i try to use prepareStmt.toString(). This method print the object reference instead.

Please help. Any help is highly appreciated.

Best Regards Anubhav Jain!

2 Answers 2

2

I'm guessing the problem is you do setXXXX to a prepared statement with wrong index (for example 0 or bigger than the number of '?' in the SQL statement)

Sign up to request clarification or add additional context in comments.

1 Comment

This also happens for PreparedStatment. Perfect explanation at javarevisited.blogspot.de/2012/01/…
1

I also faced the same issue. Later I found out that in my query string I had used quote marks around ? symbol, which is not allowed.

For example :
insert into document_table(ID, SOURCE, DESTINATION, STATUS) values('?','Active','Backup' ,'D')

is not allowed. It should have been written as:
insert into document_table(ID, SOURCE, DESTINATION, STATUS) values(?,'Active','Backup' ,'D')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.