Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package group_project;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import java.util.Scanner;
- public class Guest {
- Admin admin = new Admin();
- Scanner input = new Scanner(System.in);
- public Guest() {
- }
- /* @author Jasmin Bektic
- *
- * Method acting like LogIn form */
- public void logIn() throws Exception {
- Statement s = admin.getConnection().createStatement();
- s.executeQuery("SELECT UserName, Password FROM information");
- ResultSet rs = s.getResultSet();
- //userName and pass input
- boolean boo = true;
- while (boo) {
- System.out.println("Enter username:");
- admin.userName = input.next();
- System.out.println("Enter password:");
- admin.password = input.next();
- //Processing current data and comparing to data from database
- while (rs.next()) {
- String user = rs.getString("UserName");
- String pass = rs.getString("Password");
- if (admin.userName.equals(user) && admin.password.equals(pass)) {
- boo = false;
- break;
- }
- }
- //Supporting message, in case of input failure
- if (boo == true) System.out.println("Incorrect user name or password, try again:");
- }
- System.out.println();
- //Add name and last name in array
- PreparedStatement statement = admin.getConnection().prepareStatement("SELECT UserName FROM information WHERE information.UserName = ?");
- statement.setString(1, admin.userName);
- admin.list.add(rs.getString(1));
- rs.close ();
- s.close ();
- }
- /* Method acts like LogOut form */
- public void logOut() {
- admin.list.remove(admin.list.size() - 1);
- // ovdje ide metoda za glavni meni
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement