嗨,我已经开发了示例。这是我的代码:
public class GetMonthFromDate {
public int data() {
int count=0;
java.sql.Timestamp timeStamp = new Timestamp(System.currentTimeMillis());
java.sql.Date date = new java.sql.Date(timeStamp.getTime());
//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_order_status_history where date_time='date'");
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;
}
}
上面的代码对我不起作用。
在这里我使用了这个代码
java.sql.Timestamp timeStamp = new Timestamp(System.currentTimeMillis());
java.sql.Date date = new java.sql.Date(timeStamp.getTime());
意味着只给出输出2012-08-08
。所以只有我必须在我的代码中调用日期。但这对我不起作用。显示的返回计数值为0
. o 是错误的。2
只有正确。因为匹配的查询在我的数据库中有 2 个值。
select * from xcart_order_status_history where date_time='date'