为什么我不能使用PreparedStatement.setObject进行DATE?

时间:2016-01-06 13:15:44

标签: java jdbc oracle11g jboss6.x ojdbc

在一个非常大的Java应用程序中,根据Oracle建议的日期(Oracle JDBC Reference Information),我尝试替换:

prepareStatement.setTimestamp(new Timestamp((new Date()).getTime()));

by:

prepareStatement.setObject(1, new oracle.sql.DATE(var14, Calendar.getInstance(TimeZone.getDefault())));

但是我得到了一个SQLException“无效的列类型”。

为什么?

我尝试在最简单的情况下执行相同的代码并且正在运行!

我的假设是,在应用程序的某处,一段代码阻止我使用此代码。

什么样的代码可以做到这一点?

查询:

select * from SOMETABLE where WFSTATE IN (100, 300) OR WFTIMEOUTTIME < ? 

DDM for SOMETABLE:

CREATE TABLE "DB"."SOMETABLE" 
(   "ASSIGNEEID" VARCHAR2(128 BYTE), 
"MISSIONREPKEY" VARCHAR2(128 BYTE), 
"PROCESS_CASEFOLDERID" VARCHAR2(200 BYTE), 
"S_DISPATCH" VARCHAR2(8 BYTE), 
"S_EVENTSEQUENCE" NUMBER(10,0), 
"S_EVENTTIME" DATE, 
"S_GOALCATEGORY" VARCHAR2(64 BYTE), 
"S_WORKSTART" DATE, 
"S_WORKTIME" NUMBER(10,0),
"WFCALLERRTID" NUMBER(18,0), 
"WFCALLERWFID" NUMBER(10,0), 
"WFFLOWENTRYTIME" DATE, 
"WFFLOWEXITTIME" DATE, 
"WFLOCKTIME" DATE, 
"WFLOCKTYPE" NUMBER(10,0), 
"WFLOCKUSER" VARCHAR2(128 BYTE), 
"WFPARENTID" NUMBER(18,0), 
"WFPRIORSTEPNAME" VARCHAR2(128 BYTE), 
"WFRANDOM" NUMBER(10,0), 
"WFROUTINGTICKETID" NUMBER(18,0), 
"WFSTATE" NUMBER(10,0), 
"WFSTEPENTRYTIME" DATE, 
"WFTIMEOUTTIME" DATE, 
"WFWORKITEMID" NUMBER(18,0), 
"WFWORKSTEPNAME" VARCHAR2(128 BYTE), 
"WORKFLOWID" NUMBER(10,0), 
"WORKFLOWVERSION" NUMBER(10,0)
) (...);

Oracle DataBase版本:Oracle XE 11.2.0-1

OJdbc版本:ojdbc6 11.2.0.3

服务器:带有dataSource的JBoss AS 6:

<local-tx-datasource>
    <jndi-name>jdbc/Sonora</jndi-name>
    <connection-url>jdbc:oracle:thin:@localhost:1521:XE</connection-url>
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
    <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
    <user-name>sonora</user-name>
    <password>password</password>
    <min-pool-size>20</min-pool-size>
    <max-pool-size>20</max-pool-size>
    <prepared-statement-cache-size>50</prepared-statement-cache-size>
    <connection-property name="oracle.jdbc.timezoneAsRegion">false</connection-property>
    <new-connection-sql>alter session set nls_comp='ansi' nls_sort='GENERIC_BASELETTER' nls_language='FRENCH'</new-connection-sql>
</local-tx-datasource>

0 个答案:

没有答案