title: Type mismatch: cannot convert from java.util.Date to java.sql.Date
body: <p>I am trying to get my code to work with the SimpleDateFormat class here in the code. Does anybody knows why? Have a nice day from Julie</p>
  
  <p>When I run the code where I have imported: import java.util.Date. I get the error: 
  "The type Date is ambiguous" in the lines: </p>
  
  <pre><code>Date startDate = format.parse(req.getParameter("startDate")); 
  Date endDate = format.parse(req.getParameter("endDate"));
  </code></pre>
  
  <p>When I run the code where I have imported: import java.sql.Date; I get the error:</p>
  
  <pre><code>Date startDate = format.parse(req.getParameter("startDate")); 
  Date endDate = format.parse(req.getParameter("endDate"));
  </code></pre>
  
  <p>"Type mismatch: cannot convert from java.util.Date to java.sql.Date"</p>
  
  <pre><code>import java.sql.Date;
  
  package WorkPackage;
  
  import java.io.*;
  import java.sql.*;
  import java.text.SimpleDateFormat;
  import javax.servlet.*;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.*;
  import java.util.*;
  import java.util.Date.*;
  
  
      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
  
              String sql = "SELECT *, (Day_hours + (Day_minutes / 60)) AS Allday_hours FROM Workdata "
                      + "WHERE Date = startdate = ? AND endDate = ? ";
              PreparedStatement pst = connection.prepareStatement(sql);
  
              //Date startDate;
  
              SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
              Date startDate = format.parse(req.getParameter("startDate")); 
              Date endDate = format.parse(req.getParameter("endDate"));
              pst.setDate(1,startDate);
              pst.setDate(2, endDate);
  </code></pre>