Sunday, 11 August 2013

Repeated Update with PreparedStatement

Repeated Update with PreparedStatement

try {
PreparedStatement pstmt = conn.prepareStatement(
"UPDATE Employee SET sal = ? "
+ " WHERE eid = ?");
boolean done = false;
while (!done) {
enterData();
if (eid == 0) {
done = true;
continue;
}
pstmt.setInt(1, sal);
pstmt.setInt(2, eid);
pstmt.executeUpdate();
}
pstmt.close();
conn.close();
}
catch (SQLException e){System.err.println("Error:" + e.getMessage());}
}
static void enterData() throws IOException {
System.out.println("Enter an employee number. Enter 0 to quit.");
eid = Integer.parseInt(getData.readLine());
if (eid != 0) {
System.out.println("Enter a new salary");
sal = Integer.parseInt(getData.readLine());
}
}
}
The code works for entering an eid but after I enter sal I get the error
Error:Missing IN our OUT parameter at index:: 1
I think I think have written the SQL code wrong and/or there's an error with
pstmt.setInt(1, sal);

No comments:

Post a Comment