Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Establish a database connection and add the member in the database.
- *
- * @param user
- * @throws ClassNotFoundException
- */
- public static void addUser(cs359db.model.User user) throws ClassNotFoundException {
- // Check that we have all we need
- try {
- user.checkFields();
- } catch (Exception ex) {
- // Log exception
- Logger.getLogger(cs359db.model.User.class.getName()).log(Level.SEVERE, null, ex);
- }
- try {
- try (Connection con = CS359DB.getConnection();
- Statement stmt = con.createStatement()) {
- StringBuilder insQuery = new StringBuilder();
- insQuery.append("INSERT INTO ")
- .append(" user (USERNAME, EMAIL, PASSWORD, FIRSTNAME, LASTNAME, BIRTHDATE, COUNTRY, TOWN, ADDITIONAL) ")
- .append(" VALUES (")
- .append("'").append(user.getUserName()).append("',")
- .append("'").append(user.getEmail()).append("',")
- .append("'").append(user.getPassword()).append("',")
- .append("'").append(user.getFirstName()).append("',")
- .append("'").append(user.getLastName()).append("',")
- .append("'").append(user.getBirthDate()).append("',")
- //.append("'").append(user.getGender()).append("',")
- .append("'").append(user.getCountry()).append("',")
- .append("'").append(user.getTown()).append("',")
- .append("'").append(user.getInfo()).append("');");
- stmt.executeUpdate(insQuery.toString());
- System.out.println("#DB: The member was successfully added in the database.");
- // Close connection
- stmt.close();
- con.close();
- }
- } catch (SQLException ex) {
- // Log exception
- Logger.getLogger(cs359db.model.User.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement