Advertisement
Guest User

Class Guest

a guest
Sep 24th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. package group_project;
  2.  
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.Statement;
  6. import java.util.Scanner;
  7.  
  8. public class Guest {
  9. Admin admin = new Admin();
  10. Scanner input = new Scanner(System.in);
  11.  
  12. public Guest() {
  13.  
  14. }
  15.  
  16.  
  17.  
  18. /* @author Jasmin Bektic
  19. *
  20. * Method acting like LogIn form */
  21. public void logIn() throws Exception {
  22. Statement s = admin.getConnection().createStatement();
  23. s.executeQuery("SELECT UserName, Password FROM information");
  24. ResultSet rs = s.getResultSet();
  25.  
  26. //userName and pass input
  27. boolean boo = true;
  28. while (boo) {
  29. System.out.println("Enter username:");
  30. admin.userName = input.next();
  31. System.out.println("Enter password:");
  32. admin.password = input.next();
  33.  
  34. //Processing current data and comparing to data from database
  35. while (rs.next()) {
  36. String user = rs.getString("UserName");
  37. String pass = rs.getString("Password");
  38. if (admin.userName.equals(user) && admin.password.equals(pass)) {
  39. boo = false;
  40. break;
  41. }
  42. }
  43. //Supporting message, in case of input failure
  44. if (boo == true) System.out.println("Incorrect user name or password, try again:");
  45. }
  46. System.out.println();
  47.  
  48. //Add name and last name in array
  49. PreparedStatement statement = admin.getConnection().prepareStatement("SELECT UserName FROM information WHERE information.UserName = ?");
  50. statement.setString(1, admin.userName);
  51. admin.list.add(rs.getString(1));
  52. rs.close ();
  53. s.close ();
  54. }
  55.  
  56. /* Method acts like LogOut form */
  57. public void logOut() {
  58. admin.list.remove(admin.list.size() - 1);
  59. // ovdje ide metoda za glavni meni
  60.  
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement