为了账号安全,请及时绑定邮箱和手机立即绑定

房间预订检查

房间预订检查

汪汪一只猫 2021-08-06 10:11:00
在我的项目中,我创建了一个预订房间的系统。我的问题涉及在同一天预订房间。这是关于预订的数据库。id_book,login,email,typeroom,numroom,arrivaldate,departureddate。这是检查某个时间段内房间是否可用的代码: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.arrivaldate <= res2.departuredate)\n" +                     "AND (res2.arrivaldate <= res1.departuredate)");            String check1 = ("SELECT count(*) FROM reservation WHERE arrivaldate");            ResultSet rs2  = stmt.executeQuery(check);            ResultSet rs3 = stmt.executeQuery(check1);            if( rs2 != rs3) {            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+"'");            }问题是这样我一直在记录相同日期的相同房间,我该如何解决?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 127 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信