Good morning, I have a problem with a web application I'm creating. Premtto I'm quite new in this kind of programming. So my web application should take care of booking hotel rooms. My problem is going to make a check when someone tries to book a room, so that you can not book two equal rooms in the same period. Only that with the code written the check is not performed and the room is still booked. How could I do according to you? Thank you very much for your help.
try {
Class.forName("com.mysql.cj.jdbc.Driver");
// out.println("driver loaded");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Hotel?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", "root", "123456789");
out.println("Connect");
Statement st = con.createStatement();
Statement stmt = con.createStatement();
out.println("connection successfull");
String check = ("SELECT res1.id_prenotazione, res1.typeroom, res1.arrivaldate, res1.departuredate\n" +
"FROM reservation res1, reservation res2\n" +
"WHERE ( res1.typeroom = res2.typeroom ) \n" +
"AND res1.id_prenotazione != res2.id_prenotazione\n" +
"AND (res1.arrivaldate <= res2.departuredate)\n" +
"AND (res2.arrivaldate <= res1.departuredate)");
// ResultSet rs2 = stmt.executeQuery(check);
out.println("<h1> Stringa chek eseguita </h1>");
if (check) { // THIS DOESN't WORK OF COURSE
int rs = st.executeUpdate("insert into reservation (login,email,typeroom,numroom,arrivaldate,departuredate)values ('" + login + "','" + email + "','" + typeroom + "','" + numroom + "','" + arrivaldate + "','" + departuredate + "')");
}
String getResultSet = ("SELECT count(*) FROM reservation WHERE arrivaldate ='" + arrivaldate + "'");
String rs1 = ("SELECT count(*) FROM reservation WHERE arrivaldate");
if (getResultSet != rs1) {
int i = st.executeUpdate("DELETE FROM reservation WHERE id_prenotazione ='" + id_prenotazione + "'");
}
TABLE reservation (
id_prenotazione int(11) NOT NULL AUTO_INCREMENT,
login varchar(45) NOT NULL,
email varchar(45) NOT NULL,
typeroom varchar(45) NOT NULL,
numroom int(11) NOT NULL,
arrivaldate datetime NOT NULL,
departuredate datetime NOT NULL,
PRIMARY KEY (id_prenotazione)
TABLE users (
login varchar(45) NOT NULL,
firstname varchar(45) NOT NULL,
lastname varchar(45) NOT NULL,
password varchar(45) NOT NULL,
PRIMARY KEY (login)
if(check)isn’t working... butcheckis aString? Do you not want aboolean?