Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UserDao {
- public int save(User user, ServletContext servletContext) {
- int status = 0;
- try{
- Connection con = (Connection) servletContext.getAttribute("databaseCon");
- PreparedStatement ps=con.prepareStatement(
- "insert into user(name,surname,username,password) values (?,?,?,?)");
- ps.setString(1, user.getName());
- ps.setString(2, user.getSurname());
- ps.setString(3, user.getUsername());
- ps.setString(4, user.getPassword());
- status=ps.executeUpdate();
- }catch(Exception ex){ex.printStackTrace();}
- return status;
- }
- public User validateLogin(String username, String password, Connection connection) {
- User user = new User();
- try {
- PreparedStatement ps = connection.prepareStatement(
- "select * from user where username = ? and password = ?");
- ps.setString(1, username);
- ps.setString(2, password);
- ResultSet rs = ps.executeQuery();
- if (rs.next()) {
- user.setId(rs.getInt(1));
- user.setName(rs.getString(2));
- user.setSurname(rs.getString(3));
- user.setUsername(rs.getString(4));
- user.setPassword(rs.getString(5));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- return null;
- }
- return user;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement