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
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:
Date startDate = format.parse(req.getParameter("startDate"));
Date endDate = format.parse(req.getParameter("endDate"));
When I run the code where I have imported: import java.sql.Date; I get the error:
Date startDate = format.parse(req.getParameter("startDate"));
Date endDate = format.parse(req.getParameter("endDate"));
"Type mismatch: cannot convert from java.util.Date to java.sql.Date"
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);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…