求教!dateFormat.parse
cannot be resolved to a type
我想判断数据库里是否有date为今日日期的记录,然后做判断,下面是我的代码(不规范,请见谅!)
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"
errorPage="" %>
<%@ page import=" java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url= "jdbc:mysql://localhost:3306/graduationproject?user=root&password=123&useUnicode=true&characterEncoding=GB2312";
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
request.setCharacterEncoding("gb2312");
String datetime=new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
java.util.Date date = new dateFormat.parse(datetime);
String sql="select date from ssop where date='"+date+"'";
Integer resultnumber=statement.executeUpdate(sql);
%>
<table width="289" border="0" align="center" cellpadding="0" cellspacing="0" background="image/registerDealwith.jpg">
<tr align="center">
<td height="206">
<% if(resultnumber!=0){%>
<meta http-equiv="refresh" content="0;URL=deal_material_detection_add.jsp">
<%}else{%>
<p><b><font color="#FF0000">请进行今天的SSOP管理</font></b></p>
<meta http-equiv="refresh" content="5;URL=SSOP_report_add.jsp">
<%}%>
<%
statement.close();
connection.close();%>
<p><a href="SSOP_report_show.jsp">(如果您的浏览器无法自动跳转,请点击这里。)</a></p></td>
</tr>
</table>
</body>
</html>
一下是报错内容:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 20 in the jsp file: /before_deal_material_detection_add.jsp
dateFormat.parse cannot be resolved to a type
17: Statement statement = connection.createStatement();
18: request.setCharacterEncoding("gb2312");
19: String datetime=new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
20: java.util.Date date = new dateFormat.parse(datetime);
21: String sql="select date from ssop where date='"+date+"'";
22: Integer resultnumber=statement.executeUpdate(sql);
23: %>
好像要实现将string转换成date的包我都导入了啊,请指教!
------解决方案--------------------
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String date = df.format(new Date());
------解决方案--------------------String datetime=new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
20: java.util.Date date = new dateFormat.parse(datetime);
这个地方改为:
DateFormat df = new SimpleDateFormat(&quo