File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and the fly likes Invalid column index Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Invalid column index" Watch "Invalid column index" New topic

Invalid column index

Gaurav .Singh

Joined: Apr 06, 2010
Posts: 8
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);

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

Could somebody please help me out
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

update employee set salary = ? where salary <=

is not valid SQL. You are missing a parameter.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Gaurav .Singh

Joined: Apr 06, 2010
Posts: 8
got it.. thanks
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

You are welcome
I agree. Here's the link:
subject: Invalid column index
Similar Threads
help with a statement
setting the null and getting null
Prepared Statement Problem
java.sql.SQLException: Invalid column index
How to call procedure in JDBC