java.sql.SQLException: Missing IN or OUT parameter at index:: 1
meera meera
Greenhorn
Joined: Feb 18, 2004
Posts: 1
posted
0
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.
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
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