i've class "user" follows:
public class user{ private string firstname; private string lastname; private string[] departments; }
i want pass object of user type oracle stored procedure takes object type parameter. did achieve solution:-
1. created user_search_obj type in database follows:- create or replace type user_search_obj object ( first_name varchar2(256), last_name varchar2(256), departments table_of_values, ); 2. created table_of_values type in database follows:- create or replace type table_of_values table of varchar2(20); 3. passed user object java class follows:- object[] departments = {"1","2"}; structdescriptor objdescriptor = structdescriptor.createdescriptor("user_search_obj", conn.getmetadata().getconnection()); arraydescriptor arraydescriptor = arraydescriptor.createdescriptor("table_of_values", conn.getmetadata().getconnection()); array departmentarr = new array(arraydescriptor, conn.getmetadata().getconnection(), departments ); object[] userproperties = new object[2]; userproperties [0] = "paras";//first_name userproperties [1] = "anand";//last_name userproperties [2] = departmentarr ;//department array struct searchobj = new struct(objdescriptor, conn.getmetadata().getconnection(), userproperties ); callablestatement cstmt = conn.preparecall("pck_search2.user_search(?,?)"); cstmt.setobject(1, searchobj); cstmt.registeroutparameter(2, oracletypes.cursor); cstmt.execute();
but when run code exception follows:-
java.sql.sqlexception: inconsistent java , sql object types @ oracle.sql.structdescriptor.tooraclearray(structdescriptor.java:709) @ oracle.sql.structdescriptor.toarray(structdescriptor.java:1296) @ oracle.sql.struct.<init>(struct.java:165) @ com.ensenda.lmp.web.controller.user.main(user.java:75)
this exception comes @ following line of code:-
struct searchobj = new struct(objdescriptor, conn.getmetadata().getconnection(), userproperties );
please let me know i'm going wrong.
firstly think should arrayoutofboundexception because have declared object[2] , trying put 3rd element it. considering typo.
for original problem instead of using setobject can use *jdbcutil.setstruct(conn,cstmt,1,"user_search_obj",userproperties);*
Comments
Post a Comment