• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Number Format Exception Error

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
}
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. Yeah it works.
 
reply
    Bookmark Topic Watch Topic
  • New Topic