PreparedStatement : No value specified for parameter 2
843859Dec 15 2007 — edited Dec 15 2007I don't even know where to start explaining my problem. Basically, I wrote a class that allows me to save all the values that i need for all the setInt, setStrings etc into a Vector.
So when I create a prepareStatement, no mater what statement I write, as long as my jsp sends in the correct number of values, oughta be able to retrieve the values from the vector and process it.
So here it is...
public void processStrings(){
int size= valueStrings.size();
System.out.println("Size is "+size);
System.out.println("object at first position is"+valueStrings.elementAt(0));
System.out.println("object at 2nd position is"+valueStrings.elementAt(1));
// ListIterator list = valueStrings.listIterator();
for (int i = 0; i < size; i++){
int j = i+1;
int testInt;
int integerValue = 0;
String test = ""+valueStrings.elementAt(i);
System.out.println("value at "+i+" is "+valueStrings.elementAt(i));
System.out.println("value of i ="+i);
System.out.println("value of j ="+j);
try {
testInt = Integer.parseInt(test);
try {
integerValue = testInt;
System.out.println("Value of i = "+i+" and value of integerValue ="+integerValue);
pstmt.setInt(i, integerValue); // Suspected problem, cos went i rewrote it as pstmt.setInt(2, 3), it worked and updated the database.
System.out.println("setInt worked check sum= "+testInt);
} catch (SQLException ex) {
System.out.println("setInt didnt work");
ex.printStackTrace();
}
} catch (NumberFormatException ex) {
System.out.println("Is not a number "+test);
try {
pstmt.setString(j, ""+valueStrings.elementAt(i));
System.out.println("setString worked= "+valueStrings.elementAt(i));
} catch (SQLException ex2) {
System.out.println("Some error here");
ex.printStackTrace();
}//end catch ex2
}//end catch ex
}// end while
}// end method
// AND HERE its supposed to update.
public int pExecuteUpdate(){
int i= 0;
try {
i = pstmt.executeUpdate();
System.out.println("Wtf happened here? "+i);
} catch (SQLException ex) {
System.out.println("Something bad happened here" +i);
System.out.println(ex.getMessage());
ex.printStackTrace();
}
return i;
}
// This is the statement its supposed to process --> ("UPDATE user_login SET password = ? WHERE user_no = ?");
user_no column exists as an Integer in the database; mySql
The printlns are just for my reference to see where my program stops working.
For those interested in the output anyway... its here.
value at 0 is password
value of i =0
value of j =1
Is not a number password
setString worked=
value at 1 is 3
value of i =1
value of j =2
Value of i = 1 and value of integerValue =3
setInt worked check sum= 3
Something bad happened here0
No value specified for parameter 2
java.sql.SQLException: No value specified for parameter 2
So i don't understand, am I not supposed to use an integer variable for setInt()?
Edited by: Zaphael on Dec 15, 2007 4:52 AM