これは私のデータベースです:
ここでは、クエリの現在の日付+ステータス= 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でタイムスタンプを日付に変換する方法を説明します。そのコードを私のコードでどのように使用しますか?