Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package service;
  7.  
  8. import dao.UserDao;
  9. import db.User;
  10. import java.sql.Connection;
  11. import java.sql.DriverManager;
  12. import java.util.List;
  13.  
  14. /**
  15. *
  16. * @author Cristian
  17. */
  18. public class UserService{
  19. Connection con;
  20. private UserService(){
  21.  
  22. String url="jdbc:mysql://localhost/java3curs3";
  23. String user="root";
  24. String password="";
  25. try{ Class.forName("com.mysql.jdbc.Driver");
  26. this.con=DriverManager.getConnection(url,user,password);
  27. }catch(Exception e){
  28. e.printStackTrace();
  29. }
  30. }
  31. private static final class SingletonHolder{
  32. private static final UserService Instance=new UserService();
  33. }
  34. public static UserService getInstance(){
  35. return SingletonHolder.Instance;
  36. }
  37.  
  38. public void adaugaUser(User user){
  39. UserDao userDao=new UserDao(con);
  40. userDao.adaugaUser(user);
  41. }
  42.  
  43.  
  44. public User login(String username,String password){
  45. UserDao userDao=new UserDao(con);
  46. User user=userDao.getUserByUsername(username);
  47. if(user!=null){
  48. if(password.equals(user.getPassword())){
  49. return user;
  50. }
  51.  
  52. }
  53. return null;
  54.  
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement