oracle java和sql对象类型不一致
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31519630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Inconsistent java and sql object types
提问by cwismif
Need a little assistance with a jdbc issue.
在 jdbc 问题上需要一点帮助。
I've really struggled finding a solution to this. I don't have much experience with JDBC, and it doesn't look too newbie-friendly. If anyone can help it would be appreciated. By help I mean pointing me to other resources or even better if you can offer a direct solution.
我真的很难找到解决方案。我对 JDBC 没有太多经验,它看起来对新手不太友好。如果有人可以提供帮助,将不胜感激。帮助是指将我指向其他资源,或者如果您能提供直接解决方案,则甚至更好。
The exception is created in oracle.sql.STRUCT.java:51
异常是在 oracle.sql.STRUCT.java:51 中创建的
throw new SQLException("Cannot construct STRUCT instance, invalid connection");
and is thrown in the final line of the following code:
并在以下代码的最后一行抛出:
SimpleJdbcCall simpleJdbcCall = getSimpleJDBCCall();
con = simpleJdbcCall.getJdbcTemplate().getDataSource().getConnection().getMetaData().getConnection();
WLConnection wc = (WLConnection) con;
Connection vendorConn = wc.getVendorConnection();
con.setAutoCommit(false);
Object[] custIdentifier = { null, new Long(125435345L)};
StructDescriptor structDesc = StructDescriptor.createDescriptor("O_CUSTOMER_TYPE_CID_PID", vendorConn);
STRUCT struct = new STRUCT(structDesc, vendorConn, custIdentifier);
STRUCT[] structArray = new STRUCT[] { struct };
ArrayDescriptor des = ArrayDescriptor.createDescriptor("T_CUSTOMER_TYPE_CID_PID", vendorConn);
ARRAY array = new ARRAY(des, vendorConn, structArray);
ArrayDescriptor desEvnt = ArrayDescriptor.createDescriptor("T_EVENT_TYPE_ID", vendorConn);
ARRAY arrayEvnt = new ARRAY(desEvnt, vendorConn, events);
StructDescriptor fltDetailsStructDesc =
StructDescriptor.createDescriptor("O_FLIGHT_DETAILS", vendorConn);
DATE flightDateUTC = new DATE(flightDt);
NUMBER flightNum = new NUMBER(fltNo);
Object[] fltDetailFields = new Object[] { flightNum, flightDateUTC };
// Exception thrown in constructor below
STRUCT fltDetailsStruct = new STRUCT(fltDetailsStructDesc, vendorConn, fltDetailFields);
I'm using ojdbc6 version 11.2.0.4
我正在使用 ojdbc6 版本 11.2.0.4
The SQl object expected is:
预期的 SQL 对象是:
TYPE O_FLIGHT_DETAILS AS OBJECT
(
FLIGHT_NO NUMBER(5), -- Marketing Flight Number
UTC_DEP_DATE Date, -- Scheduled Flight departure Date in UTC
BKG_DT DATE -- Flight Booking date in UTC
);
Any help, much appreciated.
任何帮助,非常感谢。
回答by cwismif
I think the problem was as follows:
我认为问题如下:
the StructDescriptor for the 'O_FLIGHT_DETAILS' object was expecting an array containing 3 values, as per the SQL object. Since the array supplied contained only 2 values, a mismatch occurred and exception was thrown. The error message 'inconsistent java and sql object types' was accurate.
根据 SQL 对象,'O_FLIGHT_DETAILS' 对象的 StructDescriptor 需要一个包含 3 个值的数组。由于提供的数组仅包含 2 个值,因此发生不匹配并引发异常。错误消息“java 和 sql 对象类型不一致”是准确的。
I changed the fltDetailFields instantiation line to:
我将 fltDetailFields 实例化行更改为:
Object[] fltDetailFields = new Object[] { flightNum, flightDateUTC, null };
and it worked as expected.
它按预期工作。