Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql.SQLException: Missing IN or OUT parameter at index:: 1

 
meera meera
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
private static final String UPDATE_USER = "update telephone set first_name=?,last_name=?,phone=? where id=?";
.
. some code
.
statement = connection.prepareStatement(UPDATE_USER);
System.out.println("trying to update user");
statement.setInt(4,id);
result = statement.executeQuery();
if(result.next()) {
statement.setString(1,user.getFirstName());
statement.setString(2,user.getLastName());
statement.setString(3,user.getPhone());
statement.setInt(4,id);
statement.execute();
System.out.println("updated");
}
.
.
.
I am getting the following error:
java.sql.SQLException: Missing IN or OUT parameter at index:: 1
i am not knowing what the error is plz help me.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um the first part says
"statement.setInt(4,id);
result = statement.executeQuery();"
Here you are executing the query without setting the first three parameters. You cannot do that. That is why you get the error.
Mark
 
Chetan Lakshmeshwar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my case i was using 3 sqls (kinda transaction) through the same reference.
even though i had used pstmt.clearParameters() it was not having any effect.
i had to specifically say pstmt=null before i started off with the 2nd sql

my code was something like this before

pstmt=con.prepareStatement(sql1);
//execute this
pstmt.execute();
pstmt=con.prepareStatement(sql2);
pstmt.clearParameters();
//execute this

afterwards I changed it to and it worked.

pstmt=con.prepareStatement(sql1);
//execute this
pstmt.execute();
pstmt=null;
pstmt=con.prepareStatement(sql2);
//execute this
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chetu,
Allow me to suggest "close()"ing the "PreparedStatement" before reusing it (and before setting it to null, of-course)!

Good Luck,
Avi.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic