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 tim开发者_JAVA技巧es 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!
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)
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')
精彩评论