Connection con = DatabaseConnector.getConnection();
//Hard coded values. Wouldn't it be better for the form values
// to just match the database?
try {
Statement add = con.createStatement();
String state = user.getState();
user.setState(state.substring(0,2));
String sqlstatement = "INSERT USERS (USERNAME,PASSWORD,FIRST_NAME,LAST_NAME,EMAIL,ADDRESS,CITY,STATE,ZIPCODE,JOINED) " +
" VALUES('"+user.getUsername()+"','"+user.getPassword()+"','"+user.getFirstName()+"','"+user.getLastName()+"','"+user.getEmail()+"','"+user.getAddress()+"','"+
user.getCity()+"','"+user.getState()+"','"+user.getZipCode()+"','"+new SimpleDateFormat("yyyy-MM-dd").format(new Date())+"');";
add.execute(sqlstatement);
} catch (SQLException e) {
// TODO: use log4j or other loggin system instead
System.out.println("exception in adding user"+user.getUsername()+"','"+user.getPassword()+"','"+user.getFirstName()+"','"+user.getEmail()+"','"+user.getAddress()+"','"+
user.getCity()+"','"+user.getState()+"','"+user.getZipCode()+"','"+new SimpleDateFormat("MM-dd-yyyy").format(new Date())+" message"+e.getMessage());
return false;
} finally{
if(con != null)
{
try{
con.close();
}catch(SQLException e){}
}
}
return true;