title: RESTful Api and Maven
body: <p>I am trying to create a data inserting part using crud. I am not getting any errors but the data is not inserting into the database. the database connection is working correctly. these are the things that i tried. the table has 5 fields id, doctor,patient,date and venue. I am not getting any errors in the console but error while inserting data is displaying this line </p>
  
  <pre><code>$("#alertError").text("Error while saving."); 
  </code></pre>
  
  <p>jsp file</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="ISO-8859-1"&gt;
  &lt;title&gt;Appointments&lt;/title&gt;
  &lt;link rel="stylesheet" href="Views/bootstrap.min.css"&gt;
  &lt;script src="Components/jquery-3.2.1.min.js"&gt;&lt;/script&gt;
  &lt;script src="Components/appointment.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-6"&gt;
                  &lt;h1&gt;Appointment Management&lt;/h1&gt;
                  &lt;br&gt;
                  &lt;form id="formAppointment" name="formAppointment"
                  action="view.jsp"&gt;
                      Appointment ID &lt;input id="appointmentId" name="appointmentId"
                          type="text" class="form-control form-control-sm"&gt; &lt;br&gt;
                      Assign Doctor &lt;input id="assignDoctor" name="assignDoctor"
                          type="text" class="form-control form-control-sm"&gt; &lt;br&gt;
                      Assign Patient &lt;input id="assignPatient" name="assignPatient"
                          type="text" class="form-control form-control-sm"&gt; &lt;br&gt;
                      Appointment Date &lt;input id="appointmentDate" name="appointmentDate"
                          type="text" class="form-control form-control-sm"&gt; &lt;br&gt;
                      Appointment Venue &lt;input id="appointmentVenue"
                          name="appointmentVenue" type="text"
                          class="form-control form-control-sm"&gt; &lt;br&gt; 
  
                          &lt;input
                          id="btnSave" name="btnSave" type="button" value="Insert Appointment"
                          class="btn btn-primary"&gt;
                          &lt;input type="hidden" id="hide" name="hide" value=""&gt;
  
                          &lt;input type="submit"
                          id="btnView" name="btnView" type="button" value="View Appointment"
                          class="btn btn-primary"&gt;
                  &lt;/form&gt;
                  &lt;br&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Java file</p>
  
  <pre><code>public class Appointment {
  
      public String insertAppointment(String date, String venue, String docName, String patientId) {
          String output = "";
          try {
              Connection con = connect();
              if (con == null) {
                  return "Error while connecting to the database for inserting appoinment details.";
              }
  
              String insert = " insert into appointment (`app_Date`,`app_Venue`,`app_Doctor_Id`,`app_Patient_Id`) values (?,?,?,?)";
              PreparedStatement preparedStatement = con.prepareStatement(insert);
  
              preparedStatement.setString(1, date);
              preparedStatement.setString(2, venue);
              preparedStatement.setString(3, docName);
              preparedStatement.setString(4, patientId);
  
              preparedStatement.execute();
  
              output = "Inserted successfully";
  
              //output = "{\"status\":\"success\", \"data\": \"\"}";
  
          } catch (Exception e) {
              output = "Error while inserting the Appoinment.";
              System.err.println(e.getMessage());
          }
          return output;
      }
  
  }
  </code></pre>
  
  <p>API</p>
  
  <pre><code>/**
   * Servlet implementation class AppointmentAPI
   */
  @WebServlet("/AppointmentAPI")
  public class AppointmentAPI extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      Appointment appointmentObj = new Appointment();
  
      /**
       * @see HttpServlet#HttpServlet()
       */
      public AppointmentAPI() {
          super();
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
          response.getWriter().append("Served at: ").append(request.getContextPath());
      }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
          String output = appointmentObj.insertAppointment(request.getParameter("appointmentDate"),
                  request.getParameter("appointmentVenue"), request.getParameter("assignDoctor"),
                  request.getParameter("assignPatient"));
  
          response.getWriter().write(output);
      }
  
  }
  </code></pre>
  
  <p>Validation is done by JavaScript</p>
  
  <pre><code>$(document).ready(function() {
      $("#alertSuccess").hide();
  
      $("#alertError").hide();
  });
  $(document).on("click", "#btnSave", function(event) {
      $("#alertSuccess").text("");
      $("#alertSuccess").hide();
      $("#alertError").text("");
      $("#alertError").hide();
  
      var status = validateItemForm();
      if (status != true) {
          $("#alertError").text(status);
          $("#alertError").show();
          return;
      }
  
      var type = ($("#hide").val() == "") ? "POST" : "PUT";
  
      $.ajax({
          url : "AppointmentsAPI",
          type : type,
          data : $("#formAppointment").serialize(),
          dataType : "text",
          complete : function(response, status) {
              saveAppointment(response.responseText, status);
          }
      });
  });
  
  function saveAppointment(response, status) {
      if (status == "success") {
          var resultSet = JSON.parse(response);
  
          if (resultSet.status.trim() == "success") {
              $("#alertSuccess").text("Successfully saved.");
              $("#alertSuccess").show();
  
              $("#divAppointmentsGrid").html(resultSet.data);
          } else if (resultSet.status.trim() == "error") {
              $("#alertError").text(resultSet.data);
              $("#alertError").show();
  
          }
      } else if (status == "error") {
          $("#alertError").text("Error while saving.");
          $("#alertError").show();
      } else {
          $("#alertError").text("UnKnown error while saving..");
          $("#alertError").show();
      }
  
      $("#hide").val("");
      $("#formAppointment")[0].reset();
  
  }
  function validateItemForm()
  {
      /*if ($("#appointmentId").val().trim() == "")
      {
          return "Enter Appointment ID";
      }*/
  
      if ($("#assignDoctor").val().trim() == "")
      {
          return "Enter Doctor Id";
      }
  
      if ($("#assignPatient").val().trim() == "")
      {
          return "Enter Patient Id";
      }
  
      if ($("#appointmentVenue").val().trim() == "")
      {
          return "Enter Appointment Venue";
      }
      return true;
      }
  </code></pre>