I'm trying to make insertion in Oracle Db using prepared statement but it is giving me this exception : " java.sql.SQLException: Invalid column index", i searched in the forum all doing select or update no one making insertion .so i cant find what's wrong
Here is my code
Any suggestions ?
[edited to avoid horizontal scrolling on smaller screens]
Why there is a need of putting table name in double quotes , like
Also, It considered as a bad practice by having prepared call for those column names, by replacing them with '?' !
You can validate the query before executing it, just print it on the console and copy-pasting it into oracle command prompt (excuse me, If Oracle console doesn't support copy paste, I never worked on it , )
On doubt, Is it error comping from the same source code or others behind the scene code, b'coz it complains about SELECT statement
no it's the same code above which occurs this exception , the quotes will not effect , there is something else causing this exception
by the way i'm trying this query outside my code any giving the same error.
Then it might be the case that, the parameter your passing in values, may contain some string with value equal to "select", so make sure that the values which you are going to insert doesn't contain "select" strings.. Its a guess and I'm leaving for home now !
Sagar Rohankar wrote:Also, It considered as a bad practice by having prepared call for those column names, by replacing them with '?' !
I don't think it's just a bad practice (which I agree it is). I think it just plain doesn't work and is the source of your problem. Try not doing that.
Hi Paul , please more clarification ..
I agree that it won't work on any properly implemented driver. The "?" are for binding variables. These are for values. The idea is that the database can create a plan for execution and follow it regardless of the values. For this reason, setting column or table names won't work - the plan would change.