Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import connection.pool.ConnectionPool;
  2. import coupon.beans.User;
  3. import coupon.exceptions.DuplicateUser;
  4. import system.exceptions.CouponSystemException;
  5.  
  6. @Path("/register")
  7. public class Register {
  8.  
  9. Connection con;
  10.  
  11. @POST
  12. @Consumes(MediaType.APPLICATION_JSON)
  13. public void Registering(User user) throws CouponSystemException, DuplicateUser, IOException{
  14.  
  15. ConnectionPool con_pool = ConnectionPool.con_instance;
  16.  
  17. String register = "INSERT INTO user(nickname,first_name,last_name,password,email,type)values(?,?,?,?,?,?)";
  18.  
  19. PreparedStatement pre;
  20. try {
  21.  
  22. pre = con.prepareStatement(register);
  23. pre.setString(1,user.getNickName());
  24. pre.setString(2,user.getFirstName());
  25. pre.setString(3,user.getLastName());
  26. pre.setString(4,user.getEmail());
  27. pre.setString(5,user.getPassword());
  28. pre.setObject(6,user.getType());
  29. pre.execute();
  30.  
  31.  
  32. }catch(com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException e){
  33.  
  34. throw new DuplicateUser("Sorry but this user is already exist");
  35.  
  36. }catch (SQLException e1) {
  37.  
  38. throw new CouponSystemException("You have some problems that need to be fixed with your database..");
  39. }
  40. finally{
  41.  
  42. con_pool.returnConnection(con);
  43.  
  44.  
  45. try {
  46. con.close();
  47. } catch (SQLException e) {
  48.  
  49. throw new CouponSystemException("You have some problems that need to be fixed with your database..");
  50. }
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement