我写了以下java方法,当我调用它时,给了我错误
Parameter index out of range (2 > number of parameters, which is 1).
它在preparedStatement.setInt(2,p) 行给出错误;
for(int t=0;t<2 & exit;t++){
sql="SELECT allocationProb FROM trial.teacherallocation where TeacherID=?;";
preparedStatement = dbConnection.prepareStatement(sql);
preparedStatement.setString(1,var1[t]);
ResultSet rs3=preparedStatement.executeQuery();
rs3.next();
int allocationProb=rs3.getInt(1);
rs3.close();
System.out.println("INSIDE");
int p=0;
if(allocationProb==0){
p=1;
sql="UPDATE `trial`.`teacherallocation` SET `AllocationSub1`=?,` allocationProb`=? WHERE `TeacherID`=?;";
preparedStatement.setString(1,str1);
preparedStatement.setInt(2,p);
preparedStatement.setString(3,var1[t]);
preparedStatement.executeUpdate();
}
}