这是我的数据库:
在这里,我需要检查查询当前日期+状态=Q信息,并获取计数值。
这是我的代码:
public class TodayQ {
public int data() {
int count=0;
Date date = new Date(timestamp);
DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd");
System.out.println( dateFormat.format (date));
// count++;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/pro", "root", "");
PreparedStatement statement = con
.prepareStatement("select * from orders where status='Q' AND date=CURDATE()");
ResultSet result = statement.executeQuery();
while (result.next()) {
// Do something with the row returned.
count++; // if the first col is a count.
}
}
catch (Exception exc) {
System.out.println(exc.getMessage());
}
return count;
}
}
我需要编辑日期格式为 yyyy-mm-dd,现在已经得到了输出。但是我希望在数据库中使用时间戳。那么如何将时间戳转换为日期格式呢?在Java中如何使用这段代码?