Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Inconsistent java and sql object types

425960Aug 16 2005 — edited Aug 19 2005
I know that this is already in the forum, but there were no answers in the threads that I reviewed.

I have two types in the database...
an object:
CREATE OR REPLACE
TYPE TEST_OBJ AS object (ID varchar2(8), VAL number)

and a collection:
CREATE OR REPLACE
TYPE TEST_OBJ_TAB AS TABLE OF TEST_OBJ

I want to pass a nested object array to a stored proc:
CREATE OR REPLACE PROCEDURE p_TEST_PROC
(p_tab in TEST_OBJ_TAB)

IS
l_id varchar2(8);
l_val number;
BEGIN
for i in p_tab.FIRST..p_tab.LAST loop
l_id := p_tab(i).ID;
l_val := p_tab(i).VAL;
end loop;
END p_TEST_PROC;

My java:
Object[][] objs = new Object[2][2];

objs[0][0] = "12345678";
objs[1][0] = "12345678";
objs[0][1] = new Integer(1);
objs[1][1] = new Integer(2);

con = null;
String user = "user";
String password = "pwd";
String machine = "server";
String database = "db";
String port = "1521";
String url = "jdbc:oracle:thin:@" + machine + ":" + port + ":"
+ database;
String driver = "oracle.jdbc.driver.OracleDriver";
Class.forName(driver);

System.out.println(url);

con = DriverManager.getConnection(url, user, password);
con.setAutoCommit(false);

StructDescriptor desc =StructDescriptor.createDescriptor("TEST_OBJ_TAB",con);
STRUCT struct = new STRUCT(desc,con,objs);

cstmt = con.prepareCall(CSTMT_CALL);
cstmt.setObject(1,struct,Types.STRUCT);
cstmt.execute();

The SQLException is: Inconsistent java and sql object types. I am not sure what this means. Is there some type mapping that I still have to do?

Regards,

Jimmy
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 16 2005
Added on Aug 16 2005
10 comments
16,503 views