【问题标题】:The data types time and datetime are incompatible in the greater than or equal to operator数据类型时间和日期时间在大于或等于运算符中不兼容
【发布时间】:2016-08-15 11:42:47
【问题描述】:

我有一个使用 EclipseLink 和 SQL Server 的应用程序。

当我对 SQL Server 类型 Time 的列执行以下 JPQL 查询时:

VisitMasterTable.bookingTime between '08:00:00' and '08:59:00'

然后我得到以下错误:

数据类型timedatetime在大于等于运算符中不兼容。

这是怎么引起的,我该如何解决?

【问题讨论】:

  • 首先 - bookingTime 的列定义是什么?下一篇:为什么不用使用 PreparedStatement 而不是文字?
  • 列定义bookingTime time,我正在使用JPA
  • 您可以在此处包含您的查询吗?
  • JPQL查询select VisitMasterTable from VisitMasterTable as VisitMasterTable where VisitMasterTable.bookingDate = '2016-08-15' and VisitMasterTable.bookingTime between '08:00:00' and '08:59:00'
  • 生成的 SQL `SELECT .... FROM VISITMASTERTABLE t0 WHERE ((t0.BOOKINGDATE = {d '2016-08-15'}) AND (t0.BOOKINGTIME在 {t '08:00:00'} 和 {t '08:59:00'}))`之间

标签: sql-server jpa time eclipselink


【解决方案1】:

您需要将sendTimeAsDateTime=f‌​a‌​lse 添加到您的连接字符串中,例如:

jdbc:sqlserver://localhost:1433;databaseName=<db_name>;sendTimeAsDateTime=f‌​a‌​lse

【讨论】:

    猜你喜欢
    • 2014-05-14
    • 2013-06-02
    • 1970-01-01
    • 2014-02-13
    • 1970-01-01
    • 1970-01-01
    • 2013-06-25
    • 1970-01-01
    • 2012-11-17
    相关资源
    最近更新 更多