Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Number Format Exception Error

 
Rose Reid
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are trying to convert "01/01/2001" into a Integer?? What number is that supposed to represent?? Don't worry, there is an easier way to compare dates:

try that, or something similar
Jamie
[ August 16, 2002: Message edited by: Jamie Robertson ]
 
Rose Reid
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. Yeah it works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic