aspose file tools*
The moose likes JDBC and the fly likes java.sql.SQLException: Invalid column index Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException: Invalid column index" Watch "java.sql.SQLException: Invalid column index" New topic
Author

java.sql.SQLException: Invalid column index

Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

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]


Thanks,
Sherif
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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 .


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

here it is

here is the line the 865 line :
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1



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



[edited to avoid horizontal scrolling on smaller screens]
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
Try after removing the single-quotes in the values.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1


Sridhar, you are 2 seconds late..
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

it's giving me now this error : "java.sql.SQLException: ORA-00928: missing SELECT keyword" !!! :?:
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1


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

Joined: Mar 05, 2007
Posts: 483

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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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

Joined: Oct 06, 2007
Posts: 338
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

Joined: Mar 20, 2007
Posts: 317
Sridhar, you are 2 seconds late..



ops: ops: ops: ops: ops:
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
INSERT INTO"IVRLOGBck" (table name ) values(value1)


A missing space might be the reason.(If you actually pasted your code).
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

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

Joined: Mar 05, 2007
Posts: 483

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

Joined: May 26, 2003
Posts: 30973
    
159

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java.sql.SQLException: Invalid column index