• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

java.sql.SQLException: Invalid column index

 
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here it is

here is the line the 865 line :
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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



[edited to avoid horizontal scrolling on smaller screens]
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try after removing the single-quotes in the values.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sridhar, you are 2 seconds late..
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sridhar, you are 2 seconds late..




ops: ops: ops: ops: ops:
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Sheriff
Posts: 27234
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
S Shehab
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ..
 
author & internet detective
Posts: 41113
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic