Inconsistent java and sql object types
Need a little help with jdbc issue.
I was really trying to find a solution to this. I don't have much experience with JDBC and doesn't seem too new to it. If anyone can help it would be appreciated. Through help, I want to point to other resources, or even better if you can suggest a direct solution.
Exception is thrown at oracle.sql.STRUCT.java:51
throw new SQLException("Cannot construct STRUCT instance, invalid connection");
and is entered into 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 am using ojdbc6 version 11.2.0.4
Expected SQl object:
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 greatly appreciated.
source to share
I think the problem is this:
The StructDescriptor for the 'O_FLIGHT_DETAILS' object was expecting an array containing 3 values โโaccording to the SQL object. Since the provided array only contained 2 values, a mismatch occurred and an exception was thrown. The error message "java and sql inconsistent object types" was accurate.
I changed the line of the fltDetailFields instance to:
Object[] fltDetailFields = new Object[] { flightNum, flightDateUTC, null };
and it worked as expected.
source to share