我剪掉了这段代码,用于输入验证:
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 中的值正确比较。比较两个值的正确方法是什么?