File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql.SQLException: Invalid column index

 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
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]
 
Sagar Rohankar
Ranch Hand
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you print the full stack trace or the line no where this exception occurred .

It seems the problem with the column you are accessing is not present in table, pl check out the no of column present and you are accessing in that java code .
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here it is

here is the line the 865 line :
 
Sagar Rohankar
Ranch Hand
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Remove those single quotes '', and re run the application !!
Like,



[edited to avoid horizontal scrolling on smaller screens]
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try after removing the single-quotes in the values.
 
Sagar Rohankar
Ranch Hand
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sridhar, you are 2 seconds late..
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's giving me now this error : "java.sql.SQLException: ORA-00928: missing SELECT keyword" !!! :?:
 
Sagar Rohankar
Ranch Hand
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sagar Rohankar
Ranch Hand
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
Paul Campbell
Ranch Hand
Posts: 338
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error indicates you're referencing an column that does not exist in your table.

1) run your query in SQLPlus... see if it works.
and/or
2) execute desc <table_name> in SQLPlus... compare your column names to the ones listed.


 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sridhar, you are 2 seconds late..



ops: ops: ops: ops: ops:
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
INSERT INTO"IVRLOGBck" (table name ) values(value1)


A missing space might be the reason.(If you actually pasted your code).
 
Paul Clapham
Sheriff
Pie
Posts: 20190
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
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 ..
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33696
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sherif Shehab wrote:
Paul Clapham wrote:
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic