+ public EmailAddress(String address, User owner, String hash) {
+ this.address = address;
+ this.owner = owner;
+ this.hash = hash;
+ }
+
+ public void insert() {
+ if (id != 0) {
+ throw new IllegalStateException("already inserted.");
+ }
+ try {
+ PreparedStatement ps = DatabaseConnection.getInstance().prepare(
+ "INSERT INTO `email` SET memid=?, hash=?, email=?");
+ ps.setInt(1, owner.getId());
+ ps.setString(2, hash);
+ ps.setString(3, address);
+ ps.execute();
+ id = DatabaseConnection.lastInsertId(ps);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+