EMC Interview Question Software Engineer in Tests
0of 0 votesWrite a method to change the password of a valid user in the following database table. The method accepts 3 parameters userId, oldPassword, NewPassword:
......................................................
UserId Username Password
......................................................
.......................................................
The password should be changed only when the old password is valid.
Team: RSA
Country: India
Interview Type: Written Test

public void changePassword(String userId, String oldPassword, String password, Connection conn) {
- Achilles on June 03, 2012 Edit | Flag ReplyStringBuilder str = new StringBuilder();
sbr.append("Update table set password = :pass where userId = :user and password = :oldPass");
PreparedStatement psmt = conn.prepareStatement("Update table set password = :pass where userId = :user and password = :oldPass");
psmt.setString("pass",password);
psmt.setString("user",userId);
psmt.setString("oldPass",oldPassword);
int out = psmt.executeUpdate();
if (out == 1)
//successful
else
//unsuccessful
}