Passing array of objects from java to oracle.

Hi,
We have the following structure in oracle.
We have a nested table type of varchar2(50).
type var_tab is table of varchar2(50);
We have one object type with one member as varchar2 and another one as var_tab type.
type attribute_obj is object(
attrib_name varchar2(100)
,attrib_val var_tab
Then we have table type of that object type,
type table_tab is table of attribute_obj;
Then we have one object type with one member as varchar2,another member as integer and another one as table_tab type.
type prod_obj is object(
pr_name varchar2(100), tb_flag integer
,pr_attrib table_tab
Then we have table type of this object type,
type prod_tab as table of prod_obj;
So, the total structure is something like this;
'OS','OS_NAME', 'Windows'
'Linux'
'UNIX'
'OS_VERSION','XP'
'RED HAT'
'SOLARIS'
so, basically we have
x prod_tab:=prod_tab();
x(3):=prod_obj('OS',0,table_tab(attribute_obj('OS_NAME',var_tab('Windows','Linux','UNIX')),attribute_obj('OS_VERSION','XP','RED HAT','SOLARIS'))));
And this how we call the procedure ---
all_prod_comb_pkg.sp_main(x)
The procedure deifinition is -
procedure sp_main ( p_prod_arr prod_tab);
Please suggest a way so that we can implement the same structure in Java and then call the procedure using that array of objects.
regards,
Dipankar.

Dipankar,
There's a separate example of how to map Oracle OBJECTs to JDBC STRUCTs.
Study that one and combine the two. Not difficult (in my opinion :-)
Or search the JDBC forum for the words "STRUCT" and "ARRAY".
(What, you want me to do your coding for you?)
Good Luck,
Avi.

Similar Messages

  • How to pass array into xslt from java

    i have a xslt in which i am passing some parameter from java there is one parameter which is a array in java which i need to pass becouse array length is not defined so that xslt will work dynakically according to the parameter.
    right now i am passing parameter but not able to send the array parameter that's why my code is not fully dynamic
    please give suggestion.
    anagh

    it is not possible to pass array by using XSLT, you can wirite all values into a String with certain delim symbol, pass this string, then use xsl.substring() to get different values.

  • Passing Nested table or Vararray  from Java to Oracle store procedure

    I have some CSV file with arround 50,000 lines. I need to pass read those lines from Java to Oracle as a collection object.
    Pro & cons of both the options.
    Need some suggestions...
    Regards,
    Lokanath

    Hi,
    why not using External tables. Then you can in Oracle work it out by just using it as a normal table with all the profits.
    Herald ten Dam
    http://htendam.wordpress.com

  • Can i return an Array of Objects from c++ to java ??

    hello all,
    Can i return an Array of Objects from c++ to java ??
    If so how is it possible ??
    regards,
    gautam

    I suggest you look into the JNI, Java Native Interface. The answer is yes.

  • Returning objects from Java stored procedures

    I need to pass an object from Java to a Java SP which updates the object and returns the object back. The Java SP will be calling a PL/SQL procedure which returns some nested tables that I want to stick into the passed object.
    I tried using "IN OUT" for the object in the call spec but got an error that it was not "appropriate for the parameter". So, the next option seems to be to pass it in and then return it from the Java SP. I'm just wondering though what the the best approach for accomplishing this? I've looked through some of the sample code on the OTN but haven't found anything yet that really helps.

    I am trying to use custom object classes. I have setup a type map for the connection and my custom class implements SQLData. Yet, when my client tries to call the Java SP, it gets ORA-00932 complaining of inconsistent data types (expected IN conversion failed).
    I turned on some debug info (i.e. oracle.jdbc.sql=true) but it didn't provide any useful info in regards to why I'm getting this error. Unfortunately, the JDBC Developer's Guide does not provide full examples of the code.

  • How to create a stored procedure that accepts an array of args from Java?

    I am to be creating a stored procedure that accepts an array of arguments from Java. How to create this? thanks
    Sam

    Not a PL/SQL question really, but a Java one. The client call is done via ThinJDBC/OCI to PL/SQL, This call must be valid and match the parameters and data types of the PL/SQL procedure.
    E.g. Let's say I define the following array (collection) structure in Oracle:
    SQL> create or replace type TStrings as table of varchar2(4000);
    Then I use this as dynamic array input for a PL/SQL proc:
    create or replace procedure foo( string_array IN TStrings )...
    The client making the call to PL/SQL needs to ensure that it passes a proper TStrings array structure.. The Oracle Call Interface (OCI) supports this on the client side - allowing the client to construct an OCI variable that can be passed as a TStrings data type to SQL. Unsure just what JDBC supports in this regard.
    An alternative method, and a bit of a dirty hack, is to construct the array dynamically - but as this does not use bind variables, it is not a great idea.
    E.g. the client does the call as follows: begin
      foo( TStrings( 'Tom', 'Dick', 'Harry' ) );
    end;Where the TStrings constructor is created by the client by stringing together variables to create a dynamic SQL statement. A bind var call would look like this instead (and scale much better on the Oracle server side):begin
      foo( :MYSTRINGS );
    end;I'm pretty sure these concepts are covered in the Oracle Java Developer manuals...

  • Is it possible in java to pass reference of object in Java?

    Hello,
    I'm relativily new to Java but I have "solid" knowledge in C+ and C# .NET+.
    Is it possible in java to pass reference of object in Java? I read some articles about weakreferences, softreferences, etc. but it seems that it's not what I'm looking for.
    Here is a little piece of code I wrote:
    package Software;
    import java.util.Random;
    * @author Rodrigue
    public class RandomText
        private Random rand = new Random();
        private Thread t;
        private String rText = "Rodrigue";
        public RandomText()
            t = new Thread()
                @Override
                public void run()
                    try
                        while(true)
                            UpdateText();
                            sleep(100);
                    catch(InterruptedException ex)
            t.start();
        private void UpdateText()
            int i = rand.nextInt();
            synchronized (rText)
                rText = String.valueOf(i);
        public String GetText()
            return rText;
    }It's just a class which start a thread. This class updates a text with a random integer 10 times per second.
    I would like to get a reference on the String rText (like in C++ ;) yes I know, I must think in Java :D). So, like that, I could get one time the reference, thanks to the GetText function, and update the text when my application will repaint. Otherwise, I always have to call the GetText method ... which is slow, no?
    Are objects passed by reference in java? Or, my string is duplicated each time?
    Thank you very much in advance!
    Rodrigue

    disturbedRod wrote:
    Ok, "Everything in Java is passed by value. Objects, however, are never passed at all.". Reference of object is passed by value too.
    But, how to solve my problem in Java_? I have an object which is continually modified in a thread. From an another side, this object is continually repainted in a form.I'm not sure I totally understand your problem. If you pass a reference to an object, then both the caller and the method point to the same object. Changing the internal state of the object (e.g. by calling a setter method) through one reference will be observed through both references, since they both point to the same object.
    No, calling a method is not particularly slow. Especially if it's just a simple getter method that returns the value of a member variable.
    If this is happening in a multithreaded context, you'll have to use proper synchronization to ensure that each thread sees the others' changes.

  • Getting Type Mismatch Error while passing Array of Interfaces from C#(VSTO) to VBA through IDispatch interface

    Hi,
    I am facing issues like Type Mismatch while passing Array of interfaces from .NET  to VBA and vice versa using VSTO technology.
    My requirement is that ComInterfaceType needs to be InterfaceIsIDispatch.
    My Interface definition is somewhat like this
        [ComVisible(true)]
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        [Guid("AAF48FBC-52B6-4179-A8D2-944D7FBF264E")]
        public interface IInterface1
            [DispId(0)]
            IInterface2[] GetObj();
            [DispId(1)]
            void SetObj(ref IInterface2[] obj);
        [ComVisible(true)]
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        [Guid("CDC06E1D-FE8C-477E-97F1-604B73EF868F")]
        public interface IInterface2
    IF i am passing array of above interface (created in C#.Net) to VBA using GetObj API,i am getting type mismatch error in VBA while assigning the value to variable in VBA.Even assigning to variant type variable gives TypeMismatch.
    Also while passing Array of interfaces from VBA using SetObj API,excel crashes and sometimes it says method doesn't exists.
    Kindly provide some assistance regarding the same.
    Thanks

    Hi,
    I am facing issues like Type Mismatch while passing Array of interfaces from .NET  to VBA and vice versa using VSTO technology.
    My requirement is that ComInterfaceType needs to be InterfaceIsIDispatch.
    My Interface definition is somewhat like this
        [ComVisible(true)]
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        [Guid("AAF48FBC-52B6-4179-A8D2-944D7FBF264E")]
        public interface IInterface1
            [DispId(0)]
            IInterface2[] GetObj();
            [DispId(1)]
            void SetObj(ref IInterface2[] obj);
        [ComVisible(true)]
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        [Guid("CDC06E1D-FE8C-477E-97F1-604B73EF868F")]
        public interface IInterface2
    IF i am passing array of above interface (created in C#.Net) to VBA using GetObj API,i am getting type mismatch error in VBA while assigning the value to variable in VBA.Even assigning to variant type variable gives TypeMismatch.
    Also while passing Array of interfaces from VBA using SetObj API,excel crashes and sometimes it says method doesn't exists.
    Kindly provide some assistance regarding the same.
    Thanks

  • Nwdi-managed access of pcd-objects from java web dynpro

    Hi,
    im am trying to access portal pcd-objects from a java web dynpro component (namely getting and setting personalized iview properties). for locally managed web dynpro components this works fine with the code below.
    when i try the same with a nwdi managed web dynpro component i run into problems regarding references to used dcs. for instance, i need to reference used dc SAP_JTECHS/tc/epbc/pcm/adminapi/java because the build needs tcepbcpcmadminapijava.jar which is inside the mentioned dc. but access permissions of this dc don't allow the dependency. when i try to "add used dc ..." in nwds i get the error message: illegal dependency: access list does not allow use of ...
    has someone any solution for this problem? are there other ways of accessing pcd-objects from java web dynpro (nwdi managed!)?
    thanks
    heiko
    private static void savePersonalizationData(String value) {
         try {
              IAttributeSet attributeSet = (IAttributeSet) getIview(IVIEW);
              attributeSet.putAttribute(ATTRIBUTE, value);
              attributeSet.save();
         } catch (Exception e) {
    private static Object getIview(String pcdPath) throws Exception {
         Hashtable env = new Hashtable();
         env.put(
              com.sap.portal.directory.Constants.REQUESTED_ASPECT,
              com.sap.portal.pcm.admin.PcmConstants.ASPECT_SEMANTICS);
         env.put(
              Context.SECURITY_PRINCIPAL,
              WDClientUser.getCurrentUser().getSAPUser());
         env.put(
              IPcdContext.PCD_PERSONALIZATION_PRINCIPAL,
              WDClientUser.getCurrentUser().getSAPUser());
         InitialContext iCtx = new InitialContext(env);
         return iCtx.lookup(pcdPath);

    Hi Kust,
    To access the PCD objects the code you used looks ok for me but your main issues is related to the dc access permissions. This thread discussed about the similar issue. Please review this below thread.
    /message/979328#979328 [original link is broken]
    Regards
    Krishna Reddy

  • Calling inactive version of ABAP object from Java

    Hello,
    When I call an ABAP object from Java Program which version of ABAP object is called inactive or active ?
    Is there a mechanism to call the current inactive version or any other previous inactive /active versions ?
    Regards,
    Tarun

    Only the "active" version of ABAP code is active and runnable.
    You cannot run inactive versions. Like you have to compile a .java file to a .class file o make it runnable in the JVM.

  • Creating an arrays of objects from a class

    I was wondering does any one know how to create an array of objects from a class?
    I am trying to create an array of objects of a class.
    class name ---> Class objectArray[100] = new Class;
    I cant seem to make a single class but i need to figure out how to create an array of objects.
    I can make a normal class with Class object = new Class

    There are four lines of code in your for-loop that actually do something:
    for(index = 0; index < rooms.length; index++) {
    /*1*/  assignWidth.setWidth(Double.parseDouble(in.readLine()));
    /*2*/  rooms[index] = assignWidth;
    /*3*/  assignLength.setWidth(Double.parseDouble(in.readLine());
    /*4*/  rooms[index] = assignLength;
    }1.) Sets the width of an object, that has been instantiated outside the loop.
    2.) assigns that object to the current position in the array
    3.) Sets the width of a second object that has been instantiated outside the loop
    4.) assigns that other object to the current position in the array
    btw.: I bet you meant "assignLength.setLength(Double.parseDouble(in.readLine());" in line 3 ;)
    Since each position in an array can only hold one value, the first assignment (line 2) is overwritten by the second assignment (line 4)
    When I said "construct a new room-object and assign it to rooms[index]" I meant something like this:
    for(index = 0; index < rooms.length; index++) {
        Room aNewRoom = new Room();
        aNewRoom.setWidth(Double.parseDouble(in.readLine()));
        aNewRoom.setLength(Double.parseDouble(in.readLine());
        rooms[index] = aNewRoom;
    }1.) Constructs a new Object in every iteration of the for-loop. (btw: I don't know what kind of objects you're using, so this needs most likely modification!!)
    2.) set the width of the newly created object
    3.) set the length of the newly created object
    4.) assign the newly created object to the current position in the array
    -T-
    btw. this would do the same:
    for(index = 0; index < rooms.length; index++) {
        rooms[index] = new Room();
        rooms[index].setWidth(Double.parseDouble(in.readLine()));
        rooms[index].setLength(Double.parseDouble(in.readLine());
    }but be sure you understand it. Your teacher most likely wants you to explain it ;)

  • Cannot Acccess Applet Object from Java Script

    Hi,
    I am using jRE1.5, and Kava Chart Applets. Those applet jars are compiled in jdk 1.5 version. I have created one jsp where I used ,<applet> tag. The problem is when ever I am going to access the applet object from java script it is not returning the actual java applet object, when put an alert message it shows [object]. So i am not able to access the methods or the applet class.and also the screen gets hung, nothing is coming.It get stuck at the point where i tried to access the applet method like document.getElementById(applet_id).<<<some method of the applet class>>.Also it is not showing any kind of javascript error or Applet class exceptions.
    But the strange thing is, when i use jdk 1.6, the page is running fine.Also when i try to print the applet object from javascript it is showing the proper class name.
    Please help me solving the problem.

    A number of changes and improvements were made between 1.5 and 1.6 - the entire plugin is new. You need to change to 1.6, as 1.5 goes EOL about November this year and future changes to this area in 1.5 are unlikely.

  • Passing an array as parameter from java (java controls) to stored procedure

    Hi,
    I'm using java controls (BEA Weblogic Workshop 8.1) to call a stored procedure and send an array as a parameter to the stored procedure from java. The following code below throws an exception "Fail to convert to internal representation".
    Java code
    import com.bea.control.DatabaseControl.SQLParameter;
    // Here i create the java array
    int[] javaArray={12,13,14};
    //The code below is used to create the oracle sql array for the procedure
    SQLParameter[] params = new SQLParameter[1];
    Object obj0=javaArray;
    params[0] = new SQLParameter(obj0, oracle.jdbc.OracleTypes.ARRAY, SQLParameter.IN);
    // the code below calls the testFunc method in OJDBCtrl.jcx file
    String succ= dbControl.testFunc(params);
    OJDBCtrl.jcx
    * @jc:sql statement="call CMNT_TST_PROC(?))"
    String testFunc(SQLParameter[] param);
    The stored procedure used:
    TYPE SL_tab IS TABLE OF number INDEX BY PLS_INTEGER;
    Procedure cmnt_tst_proc (cmnt_tst sl_tab);
    Procedure cmnt_tst_proc (cmnt_tst sl_tab) is
    BEGIN
    dbms_output.put_line('Hello');
    END;
    I am getting the following exception
    Failure=java.sql.SQLException: Fail to convert to internal representation: [I@438af4 [ServiceException]>
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
    at oracle.jdbc.driver.DatabaseError.check_error(DatabaseError.java:861)
    at oracle.sql.ARRAY.toARRAY(ARRAY.java:210)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:7768)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7449)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7837)
    at oracle.jdbc.driver.OracleCallableStatement.setObject(OracleCallableStatement.java:4587)
    at weblogic.jdbc.wrapper.PreparedStatement.setObject(PreparedStatement.java:244)
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl._setParameter(DatabaseControlImpl.jcs:1886)
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl.getStatement_v2(DatabaseControlImpl.jcs:1732)
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl.invoke(DatabaseControlImpl.jcs:2591)
    at com.bea.wlw.runtime.core.dispatcher.DispMethod.invoke(DispMethod.java:377)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:433)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:406)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:249)
    at com.bea.wlw.runtime.jcs.container.JcsContainer.invoke(JcsContainer.java:85)
    at com.bea.wlw.runtime.core.bean.BaseContainerBean.invokeBase(BaseContainerBean.java:224)
    at com.bea.wlw.runtime.core.bean.SLSBContainerBean.invoke(SLSBContainerBean.java:109)
    at com.bea.wlwgen.StatelessContainer_ly05hg_ELOImpl.invoke(StatelessContainer_ly05hg_ELOImpl.java:153)
    Can you please let me know, what i'm doing wrong and how i can pass an array to a procedure/function using java controls.
    Any help will be highly appreciated.
    Edited by: user12671762 on Feb 24, 2010 5:03 AM
    Edited by: user9211663 on Feb 24, 2010 9:04 PM

    Thanks Michael.
    Here's the final code that i used, this might be helpful for those who face this problem
    Java Code
    // Following code gets the connection object
    InitialContext ctx = new InitialContext();
    dataSource = (DataSource)ctx.lookup("<DataSourceName>");
    conn=dataSource.getConnection();
    // Following code is used to create the array type from java
    String query="CREATE OR REPLACE TYPE STR_ARRAY AS VARRAY(3) OF NUMBER";
    dbControl.runTypeQuery(query);
    // Following code is used to obtain the oracle sql array as SQLParameter
    ArrayDescriptor desc = ArrayDescriptor.createDescriptor("<schemaName>.STR_ARRAY", conn);
    Object[] elements = new Object[3];
    elements[0] = new Integer(12);
    elements[1] = new Integer(13);
    elements[2] = new Integer(14);
    oracle.sql.ARRAY newArray = new oracle.sql.ARRAY( desc, conn, elements);
    SQLParameter[] params = new SQLParameter[1];
    params[0] = new SQLParameter(newArray, oracle.jdbc.OracleTypes.ARRAY, SQLParameter.IN);
    String succ= dbControl.testFunc(params);

  • Passing an array of objects to stored procedure(oracle)

    I have to pass an array of objects to a pl/sql stored proc.
    Its prototype is,
    proc_orderins(ordernum varchar2(14), ct newTask)
    where newTask is an array of objects:
    type task as object ( name varchar2(20),odd varchar2(8),sdd varchar2(8));
    create or replace type newTask as VARRAY(25) OF Task;
    will the following work from the java code :
    public class CriticalTask
    String name,odd,sdd;
    public CrticalTask(String name,String odd,String sdd)
    this.name=name;
    this.odd=odd;
    this.sdd=sdd;
    Object [] ctasks =new Object[7];
    for(i=0;i<7;i++)
    Object=new CrtitcalTask("x","x","x");
    String query="{call proc_orderins(?,?)}";
    CallableStatement cstmt=con.prepareCall(query);
    cstmt.setInt(123);
    cstmt.setObject(ctasks);
    cstmt.execute();
    will the above code work, when I am passing an array?

    Use code tags when you post code.
    I am rather certain that the code you posted will not work.
    Technically you should be able to use the java.sql.Array interface.
    The newest Oracle drivers might support that (you would have to investigate how to use it.)
    It is however possible that it isn't supported. If not then you will have to use one of the Oracle specific classes that is documented in the Oracle jdbc documentation.

  • Parameters passing from java to oracle forms

    How can i pass parameters out of a java environment, and into an
    oracle forms(6i) environment?
    we run on db 9i
    on windows xp.
    thanks
    yair

    Dipankar,
    There's a separate example of how to map Oracle OBJECTs to JDBC STRUCTs.
    Study that one and combine the two. Not difficult (in my opinion :-)
    Or search the JDBC forum for the words "STRUCT" and "ARRAY".
    (What, you want me to do your coding for you?)
    Good Luck,
    Avi.

Maybe you are looking for