入力検証に使用するこのコードを切り取っています。
public void validaUserID(FacesContext context, UIComponent component, Object value) throws ValidatorException, SQLException {
int findAccount = 0;
if (ds == null) {
throw new SQLException("Can't get data source");
}
// Initialize a connection to Oracle
Connection conn = ds.getConnection();
if (conn == null) {
throw new SQLException("Can't get database connection");
}
// Convert Object into String
int findValue = Integer.parseInt(value.toString());
// With SQL statement get all settings and values
PreparedStatement ps = conn.prepareStatement("SELECT * from USERS where USERID = ?");
ps.setInt(1, findValue);
try {
//get data from database
ResultSet result = ps.executeQuery();
while (result.next()) {
// Put the the data from Oracle into Hash Map
findAccount = result.getInt("USERID");
}
} finally {
ps.close();
conn.close();
}
// Compare the value from the user input and the Oracle data
if (value.equals(findAccount)) {
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
value + " Session ID is already in use!", null));
}
}
何らかの理由で、入力データがOracleの値と適切に比較されません。2つの値を比較する適切な方法は何ですか?