【发布时间】:2012-08-01 10:31:53
【问题描述】:
这是我的数据库:
这里我要查看查询当前日期+状态=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 中将时间戳转换为日期。如何在我的代码中使用该代码?
【问题讨论】:
-
Java 中有 TimeStamp 类可能是 sql.timestamp .. 看看这可能对你有帮助。
-
检查此链接以将时间戳转换为日期。 [时间戳到日期][1] [1]:stackoverflow.com/questions/2318719/…
-
日期列是什么SQL类型?
-
这不是答案。 日期列是什么 SQL 类型?
-
@krishnaveni 你想要什么样的例子?
标签: java mysql web-services soap valueconverter