title: Compare element in SQL ( Room Reservation WebApp) Java
body: <p>I have created a simple web application.
  I need to check, when someone books a room, that the arrival_date is different.
  For instance:
  Person A: books a room in data: 12/07/2018
  Person B: book a room in data: 12/07/2018 ( HE CAN'T because there is the person A yet).</p>
  <p>I have this db:</p>
  <blockquote>
  <p>hotel_booking</p>
  <p>cid, cname, email, arrival_date, departure_date, person, room, type_room,comment, status, uid.</p>
  </blockquote>
  <p>and this is my code</p>
  <blockquote>
  <p>HotelBooking.java</p>
  </blockquote>
  <pre><code>package hotel;
  
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.Statement;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  
  /**
   *
   * @author OOPs
   */
  public class Hotelbooking extends HttpServlet {
  
      /**
       * Processes requests for both HTTP &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt;
       * methods.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          response.setContentType(&quot;text/html;charset=UTF-8&quot;);
          PrintWriter out = response.getWriter();
          String s1 = request.getParameter(&quot;id&quot;);
          String s2 = request.getParameter(&quot;name&quot;);
             String s3 = request.getParameter(&quot;email&quot;);
             String s4 = request.getParameter(&quot;arrivaldate&quot;);
             String s5 = request.getParameter(&quot;departuredate&quot;);
             String s6 = request.getParameter(&quot;person&quot;);
             String s7 = request.getParameter(&quot;rooms&quot;);
             String s8 = request.getParameter(&quot;type_room&quot;);
             String s9 = request.getParameter(&quot;comment&quot;);
             String s10 = request.getParameter(&quot;status&quot;);
             
             // sesson..........
             HttpSession session=request.getSession(true);
            String s11 = (String)session.getAttribute(&quot;sessname&quot;);
  
         out.println(s11);
               
           
     
            
         try {
             
             
              Class.forName(&quot;com.mysql.jdbc.Driver&quot;);
        //  out.println(&quot;driver loaded&quot;);
       Connection  con = DriverManager.getConnection(&quot;jdbc:mysql://localhost:3306/HotelReservation&quot;,&quot;root&quot; ,&quot;123456789&quot;);
        //  out.println(&quot;Connect&quot;);
        Statement  st =  con.createStatement();
          //  out.println(&quot;conncetion successfull&quot;);
       
         
         int rs =  st.executeUpdate(&quot;insert into hotel_booking (cname,email,arrival_date,departure_date,person,room,type_room,comment,status,uid)values ('&quot;+s2+&quot;','&quot;+s3+&quot;','&quot;+s4+&quot;','&quot;+s5+&quot;','&quot;+s6+&quot;','&quot;+s7+&quot;','&quot;+s8+&quot;','&quot;+s9+&quot;','&quot;+s10+&quot;','&quot;+s11+&quot;')&quot;);
           // out.println(s1);
           // out.println(s2);
            out.println(&quot;&lt;h1&gt; Register sucsefulltttt &lt;/h1&gt;&quot;);
             
            /* if(rs == 1)
             {
             out.println(&quot;&lt;script type=\&quot;text/javascript\&quot;&gt;&quot;);
         out.println(&quot;alert('send successfully');&quot;);
         out.println(&quot;&lt;/script&gt;&quot;);
         //response.sendRedirect(&quot;home.jsp&quot;);
             }else{
         
         
         }*/
             
            response.sendRedirect(&quot;thankyoureg.jsp&quot;); 
             
             
             
          }catch(Exception e){
          out.println(&quot;nahiiiiiiiiiiiii&quot; +e);
          }
          finally {
              out.close();
          }
      }
  
      // &lt;editor-fold defaultstate=&quot;collapsed&quot; desc=&quot;HttpServlet methods. Click on the + sign on the left to edit the code.&quot;&gt;
      /**
       * Handles the HTTP &lt;code&gt;GET&lt;/code&gt; method.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          processRequest(request, response);
      }
  
      /**
       * Handles the HTTP &lt;code&gt;POST&lt;/code&gt; method.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          processRequest(request, response);
      }
  
      /**
       * Returns a short description of the servlet.
       *
       * @return a String containing servlet description
       */
      @Override
      public String getServletInfo() {
          return &quot;Short description&quot;;
      }// &lt;/editor-fold&gt;
  
  }
  </code></pre>
  <p>How can I do in your opinion?? Thanks for the help.</p>