// Create the prepared statement and use it to
// INSERT the student attributes INTO the Student table.
PreparedStatement pstmt = conn.prepareStatement(
"INSERT INTO Review VALUES (?, ?, ?, ?)");
pstmt.setInt(1, Integer.parseInt(request.getParameter("section_id")));
pstmt.setString(2, request.getParameter("quarter"));
pstmt.setInt(3, Integer.parseInt(request.getParameter("year")));
pstmt.setDate(4, ????)
任何人都可以告诉我如何处理类型Date ??
答案 0 :(得分:0)
首先,您需要将一个String解析为java.util.Date
对象。
SimpleDateFormat format = new SimpleDateFormat("dd-MMM-yyyy");
Date date = format.parse(request.getParameter("date"));
然后,您可以将java.util.Date
转换为java.sql.Date
,以便在PreparedStatement
中使用:
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
PreparedStatement pst = connection.prepareStatement(sql);
pst.setDate(4, sqlDate);