Win a copy of Spark in Action this week in the Open Source Projects forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Invalid column index

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program is as follows

dbStatement.executeUpdate("create table employee(id INTEGER constraint employee_pk primary key not null, " +
"name VARCHAR(50), salary float)");
dbStatement.executeUpdate("insert into employee values(1, 'A', 30000)");
dbStatement.executeUpdate("insert into employee values (2, 'B', 50000)");
dbStatement.executeUpdate("insert into employee values (3, 'C', 20000)");
dbStatement.executeUpdate("insert into employee values (4, 'D', 40000)");

PreparedStatement preparedStatement = dbConnection.prepareStatement("update employee set salary = ? where salary <= ");
preparedStatement.setFloat(1, 65000);
preparedStatement.setFloat(2, 40000);
preparedStatement.executeUpdate();
preparedStatement.close();
dbStatement.close();
dbConnection.close();

And I am getting the error --
Invalid column index at the line --- preparedStatement.setFloat(2, 40000);

Could somebody please help me out
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


update employee set salary = ? where salary <=


is not valid SQL. You are missing a parameter.
 
Gaurav .Singh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it.. thanks
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome
 
No more fooling around. Read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic