Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package service;
- import dao.UserDao;
- import db.User;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.util.List;
- /**
- *
- * @author Cristian
- */
- public class UserService{
- Connection con;
- private UserService(){
- String url="jdbc:mysql://localhost/java3curs3";
- String user="root";
- String password="";
- try{ Class.forName("com.mysql.jdbc.Driver");
- this.con=DriverManager.getConnection(url,user,password);
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- private static final class SingletonHolder{
- private static final UserService Instance=new UserService();
- }
- public static UserService getInstance(){
- return SingletonHolder.Instance;
- }
- public void adaugaUser(User user){
- UserDao userDao=new UserDao(con);
- userDao.adaugaUser(user);
- }
- public User login(String username,String password){
- UserDao userDao=new UserDao(con);
- User user=userDao.getUserByUsername(username);
- if(user!=null){
- if(password.equals(user.getPassword())){
- return user;
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement