【发布时间】:2012-08-05 03:46:12
【问题描述】:
您好,我必须在检查查询并返回计数值后将时间戳转换为日期。 我的数据库有日期(1344399208,1344399269),状态(Q,Q)。 这是我的代码:
public class GetCurrentDateTime {
public int data(){
int count=0;
java.sql.Timestamp timeStamp =new Timestamp(System.currentTimeMillis());
java.sql.Date date = new java.sql.Date(timeStamp.getTime());
System.out.println(date);
//count++;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
PreparedStatement statement = con.prepareStatement("select * from xcart_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)格式。它成功完成了。我得到的输出是 2012-08-08。但我必须检查查询today date+status=Q .so 该日期如何保存在变量中并在查询中调用该变量。so 如何为上述条件编写查询。检查条件并显示返回计数值我的tomcat控制台。怎么办。请帮帮我
【问题讨论】:
标签: java mysql date jdbc timestamp