I am getting a Number Format Exception Error I was hoping someone could tell me why.
I am saving a string variable to an Access database, ExpirationDate and want to retrieve it so I can compare the current date with it to see if a user's password has expired.
Here is the code:
public boolean expirationDate(String userID, String password) throws Exception {
// the return value
boolean expiredDate = false;
// the statement and resultset object
Statement stmt = null;
ResultSet rs = null;
try {
// the sql statement string
String sql = "SELECT * FROM PasswordTable " +
"WHERE USERID='" + userID + "' " +
"AND USERPWD='" + password + "'";
// create the resultset
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next())
{
String ed = rs.getString("ExpirationDate");
// get expiration date from the database
// String ed = rs.getString("ExpirationDate");
// create calendar object for current date
Calendar cal = Calendar.getInstance();
cal.setTime(new java.util.Date());
java.util.Date ts = cal.getTime();
// format current date
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
String time_stamp = formatter.format(ts);
if ((Integer.parseInt(time_stamp) == Integer.parseInt(ed)) || (Integer.parseInt(time_stamp) > Integer.parseInt(ed))) {
// set the valid flag
expiredDate = true;
} else {
expiredDate = false;
}
}
} catch (Exception ex) {
expiredDate = false;
ex.printStackTrace();
}
// close the statement and result
close(stmt, rs);
// return the valid value
return expiredDate;
}