Java Prepared语句等于时间戳字段上的日期比较

时间:2018-10-02 13:56:38

标签: java postgresql jdbc timestamp postgresql-9.5

我在表中有两个带有时间戳的字段。我想比较日期是否相等。 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);
    }

1 个答案:

答案 0 :(得分:0)

在while循环中attDate = rsAtt.getTimestamp(“ attandencedate”); 用getDate()更改它;类型。