嗨,我必须在检查查询并返回计数值后将时间戳转换为日期。我的数据库有日期(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。但我今天必须检查查询日期+ status = Q .so如何将该日期保存在变量中并在查询中调用该变量。so如何为上述条件编写查询。检查条件并在我的tomcat控制台上显示返回计数值。如何做。请帮我