Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package grupniProjektHotel;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.Scanner;
- public class Admin {
- public int ID, age, roomNum, balance;
- public String firstName, lastName, gender, identityCard, userName, password, roomType;
- public String checkInTime, checkOutTime, service, loggedIn;
- private static Connection conection;
- /*
- * @author Jasmin Bektic
- *
- * Method confirms connection
- */
- public Connection getConnection() {
- try {
- String driver = "com.mysql.jdbc.Driver";
- String url = "jdbc:mysql://localhost:3306/hotel";
- String user = "root";
- String pass = "";
- Class.forName(driver);
- Connection con = DriverManager.getConnection(url, user, pass); // Connecting
- // with
- // provided
- // url,userName
- // and
- // pass
- return con;
- } catch (Exception e) { // Catch errors
- System.out.println(e);
- }
- return null;
- }
- public void checkGuest() {
- }
- public void enterInfo() throws SQLException {
- Connection con = getConnection();
- String sql = "INSERT INTO information (information.FirstName,'lastName',Information.Gender,'identityCard','age','roomNum','roomType','checkInTime','userName','password') VALUES (?,?,?,?,?,?,?,?,?,?)";
- PreparedStatement statement = con.prepareStatement(sql);
- // statement.setString(1, s);
- // statement.setString(2, s);
- // statement.setString(3, s);
- statement.executeUpdate(sql);
- // ResultSet result = statement.executeQuery();
- // ResultSetMetaData rsmd = result.getMetaData();
- }
- /*
- * @ author Davor Sadikovic
- *
- * Method prints occupied rooms and prompts user to enter room number
- * Retruns room number
- */
- public int checkAvailableRoom() throws SQLException {
- Scanner input = new Scanner(System.in);
- int roomNumber = 0;
- try {
- //Connects to server
- Connection conn = getConnection();
- String query = "SELECT Room Number AND Room Type FROM information";
- PreparedStatement ps = conn.prepareStatement(query);
- ResultSet rs = ps.executeQuery();
- //Prints occupied rooms
- System.out.println("Rooms that are occupied are: \n");
- while (rs.next()) {
- System.out.println("Room number: " + rs.getInt(roomNum) + "\tRoom Type: " + rs.getString("Room Type"));
- }
- //Prompts user to enter a room number
- System.out.println("\nEnter room number: ");
- roomNumber = input.nextInt();
- //Checks if room number is occupied and if it is it calls method again
- while (rs.next()) {
- if (roomNumber == rs.getInt(roomNum)) {
- System.out.println("Room number you entered is occupied. ");
- checkAvailableRoom();
- }
- }
- input.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return roomNumber;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement