Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import connection.pool.ConnectionPool;
- import coupon.beans.User;
- import coupon.exceptions.DuplicateUser;
- import system.exceptions.CouponSystemException;
- @Path("/register")
- public class Register {
- Connection con;
- @POST
- @Consumes(MediaType.APPLICATION_JSON)
- public void Registering(User user) throws CouponSystemException, DuplicateUser, IOException{
- ConnectionPool con_pool = ConnectionPool.con_instance;
- String register = "INSERT INTO user(nickname,first_name,last_name,password,email,type)values(?,?,?,?,?,?)";
- PreparedStatement pre;
- try {
- pre = con.prepareStatement(register);
- pre.setString(1,user.getNickName());
- pre.setString(2,user.getFirstName());
- pre.setString(3,user.getLastName());
- pre.setString(4,user.getEmail());
- pre.setString(5,user.getPassword());
- pre.setObject(6,user.getType());
- pre.execute();
- }catch(com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException e){
- throw new DuplicateUser("Sorry but this user is already exist");
- }catch (SQLException e1) {
- throw new CouponSystemException("You have some problems that need to be fixed with your database..");
- }
- finally{
- con_pool.returnConnection(con);
- try {
- con.close();
- } catch (SQLException e) {
- throw new CouponSystemException("You have some problems that need to be fixed with your database..");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement