title: Error in MySQL statement in WHERE clause
body: <p>I am trying to get a value "startDate" and "endDate" from my form:</p>
  
  <pre><code>&lt;form&gt;
          &lt;input id="startDate"/&gt;                     
          &lt;input id="endDate"/&gt;
      &lt;/form
  </code></pre>
  
  <p>The form is connected to a javascript, which from there goes to a MySQL database. The problem is that every time I run SQL query in my servlet i get the following error:</p>
  
  <p>SQLException caught: Unknown column 'startDate' in 'where clause'</p>
  
  <p>Can anybody see what I am doing wrong?
  have a nice day from Julie</p>
  
  <p>EDITED CODE: I have tried to edited my code. I now get the error at: Date startDate; , where it says: "Duplicate local variable startDate". That is of course because I have 
  String startDate = req.getParameter("startDate"); . I dont have to use this anymore?
          package WorkPackage;</p>
  
  <pre><code>import java.io.*;
  import java.sql.*;
  import javax.servlet.*;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.*;
  
  @WebServlet("/getHoursSQL")
  public class getHoursSQL extends HttpServlet{
  
      private static final long serialVersionUID = 1L;
  
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          doPost(request, response);
      }
  
      public void doPost(HttpServletRequest req, HttpServletResponse res) 
          throws ServletException, IOException{
  
          String connectionURL = "jdbc:mysql://localhost/NekiWork";
          Connection connection=null;
          String startDate = req.getParameter("startDate");
          String endDate= req.getParameter("endDate");
          try {
              //Load database driver
              Class.forName("com.mysql.jdbc.Driver");
              //Connection to the database
              connection = DriverManager.getConnection(connectionURL, "root", ""); 
              //Getting the data from database
              Date startDate;                                             
              String sql = "SELECT *, (Day_hours + (Day_minutes / 60)) AS Allday_hours FROM Workdata WHERE Date = ?";
              PreparedStatement pst = connection.prepareStatement(sql);
                  pst.setDate(1,startDate);
                  //pst.setString(2,endDate);
              //Show the result from database
                  ResultSet rs = pst.executeQuery();
  
              float Allday_hours_sum = 0;
                  while (rs.next()){                                      
                      Allday_hours_sum += rs.getFloat("Allday_hours"); 
  
  
              }   
                  res.setContentType("text/html;charset=UTF-8");          
                  res.getWriter().print(Allday_hours_sum); 
  
  
              pst.close();
  
  
          }
          catch(ClassNotFoundException e){
  
              System.out.println("Couldn't load database driver: " + e.getMessage());
          }
          catch(SQLException e){
              System.out.println("SQLException caught: " + e.getMessage());
          }
          catch (Exception e){
              System.out.println(e);
          }
          finally {
  
              try {
                  if (connection != null) connection.close();
              }
              catch (SQLException ignored){
                  System.out.println(ignored);
              }
          }
      }
  }
  </code></pre>
  
  <p>EDITED:
  This is how my database looks like:
  <a href="http://postimg.org/image/3sbzplg9d/" rel="nofollow">http://postimg.org/image/3sbzplg9d/</a></p>
  
  <p>This is my javascript where I am getting some values out from my calendar:</p>
  
  <pre><code>&lt;form&gt;
          &lt;input id="startDate"/&gt;                     
          &lt;input id="endDate"/&gt;
      &lt;/form&gt;
      &lt;div id="startresult"&gt;&lt;/div&gt;
      &lt;div id="endresult"&gt;&lt;/div&gt;
      &lt;script&gt;
  
      $(function(){
          $("#startDate").datepicker({
              dateFormat: 'yy-mm-dd',
              onSelect: function(dateText,inst){
                  $('.selected-date').html(dateText);
  
                  $.ajax({
                        url: "../getHoursSQL",
                        type: "post",
                        data: JSON,
                        success: function(data){
                            start: $("#startDate").val();
                            alert("success");
                            $("#startresult").html(data);
  
                        },
                        error:function(){
                            alert("failure");
                            $("#startresult").html('there is error while submit');
                        }  
                      });
              }
          });
      });
  
      $(function(){
              $("#endDate").datepicker({
                  dateFormat: 'yy-mm-dd',
                  onSelect: function(dateText,inst){
                      $('.selected-date').html(dateText);
  
                      $.ajax({
                            url: "../getHoursSQL",
                            type: "post",
                            data: JSON,
                            success: function(data){
                                end: $("#endDate").val();
                                alert("success");
                                $("#endresult").html(data);
                            },
                            error:function(){
                                alert("failure");
                                $("#result").html('there is error while submit');
                            }  
                          });
                  }
              });
          });
  
  &lt;/script&gt;
  </code></pre>