@Override public boolean create(User u) { Connection conn = DbUtils.getConnection(); PreparedStatement ps = null; final String query = PropertyContainer.get(Const.INSERT_USER); try { ps = conn.prepareStatement(query); int k = 1; ps.setString(k++, u.getEmail()); ps.setString(k++, u.getPassword()); ps.setString(k++, u.getFirstName()); ps.setString(k++, u.getLastName()); ps.setString(k++, u.getDocumentTag()); ps.setLong(k++, u.getRole().getId()); int count = ps.executeUpdate(); conn.commit(); if (count > 0) { // user.setId ?? rs = getGeneratedKeys... return true; } return false; } catch (SQLException e) { DbUtils.rollback(conn); LOG.error(e.getMessage()); throw new DbException(e.getMessage(), e); } finally { DbUtils.close(conn, ps, null); } }
private User extractUser(ResultSet rs) throws SQLException { User user = new User(); user.setId(rs.getLong("id")); user.setEmail(rs.getString("email")); user.setPassword(rs.getString("password")); user.setFirstName(rs.getString("f_name")); user.setLastName(rs.getString("l_name")); user.setRole(Role.get(rs.getLong("role_id"))); return user; }