有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

jooq比较了两个日期,它不喜欢java。sql。日期

我收到以下代码错误:

Date todayDate = new Date();
SimpleDateFormat dataDateFmt = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat dataTimeFmt = new SimpleDateFormat("HHmmss");
java.sql.Date nowDate = java.sql.Date.valueOf(dataDateFmt.format(todayDate));

selectFrom = DSL.using(connection)
        .select(Msg.MSG.MSGKEY, Msg.MSG.MSGSTS, Msg.MSG.MSGTIT,
                DSL.concat(Msg.MSG.MSGTXT1, Msg.MSG.MSGTXT2, Msg.MSG.MSGTXT3),
                DSL.date(Msg.MSG.MSGCDAT), Msg.MSG.MSGCTIM,
                DSL.date(Msg.MSG.MSGRDAT), DSL.date(Msg.MSG.MSGEDAT), 
                Msg.MSG.MSGLUID)
        .from(Msg.MSG)
        .where(Msg.MSG.MSGFID.equal("SYS")
        .and(Msg.MSG.MSGSTS.equal("NEW"))
        .and(Msg.MSG.MSGTYP.equal("WEBF"))
        .and(Msg.MSG.MSGGRP.equal("ALL"))
        .and(Msg.MSG.MSGSDAT.lt(nowDate)));

最后一行的错误是“type字段中的method lt(Timestamp)不适用于参数(Date)”。我正在做一些与我所看到的非常相似的事情


共 (1) 个答案

  1. # 1 楼答案

    必须将lt中定义的相同数据类型传递给Msg.MSG.MSGSDAT

    解决方案(不太通用,但有效):

                    selectStmt = DSL.using(connection)
                            .select(Msg.MSG.MSGKEY, Msg.MSG.MSGSTS, Msg.MSG.MSGTIT,
                                    DSL.concat(Msg.MSG.MSGTXT1, Msg.MSG.MSGTXT2, Msg.MSG.MSGTXT3),
                                    DSL.date(Msg.MSG.MSGCDAT), Msg.MSG.MSGCTIM,
                                    DSL.date(Msg.MSG.MSGRDAT), DSL.date(Msg.MSG.MSGEDAT), Msg.MSG.MSGLUID)
                            .from(Msg.MSG)
                            .where(Msg.MSG.MSGFID.equal("SYS")
                                    .and(Msg.MSG.MSGSTS.equal("NEW"))
                                    .and(Msg.MSG.MSGTYP.equal("WEBF"))
                                    .and(Msg.MSG.MSGGRP.equal("ALL"))
                                    .and(DSL.date(Msg.MSG.MSGSDAT).lt(nowDate)
                                            .or(DSL.date(Msg.MSG.MSGSDAT).eq(nowDate)
                                                    .and(Msg.MSG.MSGSTIM.ge(nowTime))))
                                    .and(DSL.date(Msg.MSG.MSGEDAT).gt(nowDate)
                                            .or(DSL.date(Msg.MSG.MSGEDAT).eq(nowDate)
                                                    .and(Msg.MSG.MSGETIM.le(nowTime))))
    

    关键是where子句中的DSL.date(Msg.MSG.MSGSDAT)DSL.date(Msg.MSG.MSGEDAT)