user627898
user627898

Reputation: 21

Getting java.sql.SQLException: Invalid column index while inserting into table

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!

Upvotes: 2

Views: 18795

Answers (2)

Abhishek
Abhishek

Reputation: 37

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')

Upvotes: 1

nanda
nanda

Reputation: 24788

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)

Upvotes: 2

Related Questions