Patasuss

Untitled

Jan 5th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. package com.journaldev.jsf.dao;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. import com.journaldev.jsf.util.DataConnect;
  9.  
  10. public class LoginDAO {
  11.  
  12. public static boolean validate(String user, String password) {
  13. Connection con = null;
  14. PreparedStatement ps = null;
  15.  
  16. try {
  17. con = DataConnect.getConnection();
  18. ps = con.prepareStatement("Select uname, password from Users where uname = ? and password = ?");
  19. ps.setString(1, user);
  20. ps.setString(2, password);
  21.  
  22. ResultSet rs = ps.executeQuery();
  23.  
  24. if (rs.next()) {
  25. return true;
  26. }
  27. } catch (SQLException ex) {
  28. System.out.println("Login error -->" + ex.getMessage());
  29. return false;
  30. } finally {
  31. DataConnect.close(con);
  32. }
  33. return false;
  34. }
  35. }
Add Comment
Please, Sign In to add comment