derby - 比较Derby中的时间戳和日期

标签 derby

我需要比较SELECT查询中的日期和时间戳。通常,大多数其他数据库平台(MySQL,MSSQL,Oracle等)都支持此功能,但在Derby中会引发以下错误:

Caused by: java.sql.SQLSyntaxErrorException: Comparisons between 'DATE' and 'TIMESTAMP' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1')



我不想使用CAST,因为我无法更改SQL查询。这是Derby的bug,将在某个时间得到修复吗?我当前正在使用Derby 10.8.2.2。

谢谢!

最佳答案

如果您是从Java程序进行连接,则可以使用各种getxxx()方法来获取时间戳的特定部分(这些方法实际上是从Java.util.date继承的)

参见文档http://docs.oracle.com/javase/7/docs/api/java/util/Date.html

并检查getDate(),getDay(),getHour()...的方法

关于derby - 比较Derby中的时间戳和日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11017780/

相关文章:

java - 连接到 derby 数据库时使用什么文件路径格式?

Java/SQL 查找重复项

java - 如何将 ArrayList 数据添加到 Derby 中的相同#?

sql - 在java中使用sql DATEADD函数

Spring 的 JDBCTemplate IllegalArgumentException : datasource required

java - 使用 Apache Derby 运行 TestDB 程序 - java.sql.SQLException : The url cannot be null

java - 继续对象序列化还是使用数据库?

GitHub 分发版的 Java DB 路径

derby - 安装WL应用程序时的“A lock could not be obtained”

java.sql.sqlsyntaxerrorexception :comparison between numeric and char(ucs_basic) are not supported