简体   繁体   English

Spring Jdbc将java.sql.timestamp绑定到Oracle日期问题

[英]Spring Jdbc binding java.sql.timestamp to oracle date issue

I am currently using Spring's NamedParameterJdbcTemplate to inject some values into an sql. 我目前正在使用Spring的NamedParameterJdbcTemplate将一些值注入sql。 I am having performance issues when I inject two java.sql.Timestamp values into the sql who's oracle column is of type DATE and executing. 当我将两个java.sql.Timestamp值注入到oracle列为DATE类型并执行的sql中时,出现性能问题。

It is extremely slow (approx. 4 minutes) but when I run it through sql developer it executes in less than a second since I have an index on that DATE column. 它非常慢(大约4分钟),但是当我通过sql developer运行它时,它执行不到一秒钟,因为我在该DATE列上有一个索引。 Here is a snippet of my debug log: 这是我的调试日志的片段:

select * from test_table.test_column where eventts >= :startDate and eventts <= :endDate and loginname= :loginname and channelind= :channelind
2014-04-21 15:02:50 48416 [http-8080-1] DEBUG org.springframework.jdbc.core.JdbcTemplate  - Executing prepared SQL query
2014-04-21 15:02:50 48417 [http-8080-1] DEBUG org.springframework.jdbc.core.JdbcTemplate  - Executing prepared SQL statement [select * from test_table.test_column where eventts >= ? and eventts <= ? and loginname= ? and channelind= ?]
2014-04-21 15:02:50 48417 [http-8080-1] DEBUG org.springframework.jdbc.datasource.DataSourceUtils  - Fetching JDBC Connection from DataSource
2014-04-21 15:02:50 48438 [http-8080-1] DEBUG org.springframework.jdbc.core.StatementCreatorUtils  - Setting SQL statement parameter value: column index 1, parameter value [2014-04-21 12:02:38.0], value class [java.sql.Timestamp], SQL type 93
2014-04-21 15:02:50 48439 [http-8080-1] DEBUG org.springframework.jdbc.core.StatementCreatorUtils  - Setting SQL statement parameter value: column index 2, parameter value [2014-04-22 00:00:00.0], value class [java.sql.Timestamp], SQL type 93
2014-04-21 15:02:50 48439 [http-8080-1] DEBUG org.springframework.jdbc.core.StatementCreatorUtils  - Setting SQL statement parameter value: column index 3, parameter value [MY_LOGIN], value class [java.lang.String], SQL type unknown
2014-04-21 15:02:50 48439 [http-8080-1] DEBUG org.springframework.jdbc.core.StatementCreatorUtils  - Setting SQL statement parameter value: column index 4, parameter value [WEB], value class [java.lang.String], SQL type unknown

What am I missing here? 我在这里想念什么? Is Oracle casting the values to a TIMESTAMP resulting in losing the index I have on the "eventts" DATE column? Oracle是否将值强制转换为TIMESTAMP从而导致丢失“ eventts” DATE列上的索引?

I think your guess is right. 我想你的猜测是对的。 When you have 当你有

select something from some_table where column1 = :val1

and va1 is not of the same type as column1, Oracle will do: 并且va1与column1的类型不同,Oracle将这样做:

select something from some_table where to_val1type(column1) = :val1

Function to_val1type doesn't exists, it will decided by context (TO_DATE, TO_NUMBER, etc..) 函数to_val1type不存在,它将由上下文(TO_DATE,TO_NUMBER等)决定。

either make your parameter of the same type, or use TO_XXX fuctnion yourself. 或者使您的参数具有相同的类型,或者自己使用TO_XXX功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM