我在表中有两个带有时间戳的字段。我想比较日期是否相等。 attandencedate :: date =?不起作用。
以下是我的代码:
String AttendaceSql = "SELECT * FROM attandence WHERE attandencedate::date = ? AND userid=?";
PreparedStatement pstmtAttendance = null;
pstmtAttendance = DB.prepareStatement (AttendaceSql);
ResultSet rsAtt = null;
try {
Date dateFormat = new Date(logdate.getTime());
pstmtAttendance.setDate(1, dateFormat);
pstmtAttendance.setInt(2, userID);
rsAtt = pstmtAttendance.executeQuery ();
while (rsAtt.next ())
{
flag=true;
AttendaceId = rsAtt.getInt("attandence_id");
UserId= rsAtt.getInt("userid");
attDate = rsAtt.getTimestamp("attandencedate");
System.out.println(AttendaceId+","+UserId+","+logdate+","+attDate);
}
答案 0 :(得分:0)
在while循环中attDate = rsAtt.getTimestamp(“ attandencedate”); 用getDate()更改它;类型。