Passing array as arguments

im very new to java, dont know much about it.can any one please tell me how ot pass array or array list as a argument to a class

this is my main class where it calls a readfile class to read contents of file
import java.awt.List;
import java.io.IOException;
public class Sample {
public static List alist = new List();
public static void main(final String[] args) throws IOException {
new Readfile().readFromFile("c:/sam.txt");
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
this is readfile class which reads from file having comma as a delimiter and store it in an array list.
class Readfile {
* Declaration of arraylist.
static List alist = new ArrayList();
public void readFromFile(final String filename) throws IOException {
BufferedReader bufferedReader = null;
// Construct the BufferedReader object
bufferedReader = new BufferedReader(new FileReader(filename));
String line;
while ((line = bufferedReader.readLine()) != null) {
// storing in to arraylist
StringTokenizer st1 = new StringTokenizer(line, ",");
while (st1.hasMoreTokens()) {
alist.add(st1.nextToken());
//here just im printing the elements from arraylist.
for (int j = 0; j < alist.size(); j++) {
System.out.println(alist.get(j));
if (bufferedReader != null) {
bufferedReader.close();
//converting arraylist to array;
String[] strArray = new String[50];
alist.toArray(strArray);
//passing array as argument
Area area1 = new Area(strArray);
area1.calc();
area1.print();
Here is the class for area
class Area {
String[] alist1 = new String[50];
private int[] array = new int[50];
private int[] array1 = new int[50];
public Area(final String[] alist) {
alist1 = alist;
void calc() {
* for (int i = 0; i < 2 - (alist1.length); i = i + 2) { array1[i] =
     (Integer.valueOf(alist1).intValue() * Integer .valueOf(alist1[i ]).intValue());
* To print the Area.
void print() {
System.out.println("Area of Rectangles ");
for (int i = 0; i < array1.length; i++) {
System.out.println(array1[i]);
im not sure how standard my code is .please guide me

Similar Messages

  • How can i pass array as argument in magento api method calling using sudzc API in iphone Native APP

    0down votefavorite
    I am implementing magento standard api method in native iphone app. I use webservice generated by sudzc. To call method I use:
    [service call:self action:@selector(callHandler:) sessionId:@" " resourcePath:@" " args:@""];
    When I used methods e.g. cart.info or product.info in which I have to pass one parameter; it gives valid response. But when I used method e.g. cart_product.add in which I have to pass an argument as value of array it gives error
    SQLSTATE[42000]: Syntax error or access violation:
        1064 You have an error in your SQL syntax;
        check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
    I have tested in SOAP UI also. There also it gives me same error. But same method works in PHP file. Even I tried by creating same soap request which I created using JavaScript but still it doesn't work.
    Can anyone help me to pass array as a parameter using sudzc api to call magento web services?

    There is an error in your SQL.

  • Passing array of objects to the procedure

    Hi I have written a procedure to accept array of objects as input . it worked fine.
    this is the only input parameter in my procedure.
    But now I tried to add an out put parameter of type varchar2 to my procedure to send some return value but it gives me an error
    PLS-00410: duplicate fields in RECORD,TABLE or argument list are not permitted.
    please suggest cant i pass any other arguments when using a record or object array as parameter?
    this is my code
    CREATE OR REPLACE TYPE PREF_OBJ_TYPE as object (
    PREF_CD  varchar2(20),
    USR_ID   VARCHAR2(20),
    PROD_CD  VARCHAR2(50),
    DFLT_PREF_VAL_TX VARCHAR2(250),
    USR_PREF_VAL_TX VARCHAR2(250),
    CRE_USR_ID VARCHAR2(20),
    UPDT_USR_ID VARCHAR2(20) );
    CREATE OR REPLACE TYPE PREF_ARRAY is table of PREF_OBJ_TYPE;
    CREATE OR REPLACE procedure MMM(in_pref PREF_ARRAY,v_err out varchar2 )
    is
    v_prod_dim_nb NUMBER;
    v_usr_dim_nb  NUMBER;
    v_count NUMBER;
    v_err varchar2(50);
    begin
    for i in  in_pref.first.. in_pref.last
    LOOP
    /* Derive the product and user dim numbers */
    select prod_dim_nb into  v_prod_dim_nb from prod_dim where prod_cd=in_pref(i).prod_cd ;
    select usr_dim_nb into v_usr_dim_nb from usr_xref where usr_id=in_pref(i).usr_id and sys_id='ACCESS';
    /* check if the record already exist in usr_prod_pref corresponding to that  user,prod,pref */
    select count(1) into v_count from usr_prod_pref_test where prod_dim_nb=v_prod_dim_nb and usr_dim_nb=v_usr_dim_nb and pref_cd=in_pref(i).pref_cd;
    if v_count=0 then
    BEGIN
    INSERT INTO USR_PROD_PREF_TEST values(v_usr_dim_nb,in_pref(i).pref_cd,v_prod_dim_nb,in_pref(i).DFLT_PREF_VAL_TX,in_pref(i).usr_PREF_VAL_TX,'Active',NULL,
    in_pref(i).cre_usr_id,sysdate,in_pref(i).updt_usr_id,NULL);
    END;
    else
    update USR_PROD_PREF_TEST set USR_PREF_VAL_TX=in_pref(i).USR_PREF_VAL_TX,DFLT_PREF_VAL_TX=in_pref(i).DFLT_PREF_VAL_TX,UPDT_USR_ID=in_pref(i).updt_usr_id,updt_dt=sysdate,cre_usr_id=in_pref(i).cre_usr_id where
    prod_dim_nb=v_prod_dim_nb and usr_dim_nb=v_usr_dim_nb and pref_cd=in_pref(i).pref_cd;
    end if;
    end loop;
    commit;
    v_err:='abc';
    end;
    /Edited by: raj_fresher on Oct 9, 2009 6:56 AM

    okay i was wondering.... if he knew the error code in advance i thought user defined messages have numbers like -20000 to 209999 or something like that..
    neverthless one final question ....
    Now that my procedure is ready .. i have 2 final questions for this thread
    1) is my usage of errorcode and error message to return to the calling application correct?
    2) how to test this procedure in sql plus (or) toad?
    i mean how to call?
    exec modify_user_preferences(value, ?????(what should  i write here for output variable ) ) ?? i want to check what value is it returning?
    CREATE OR REPLACE procedure MODIFY_USER_PREFERENCES2(in_pref PREF_ARRAY,v_status_message out varchar2  )
    is
    v_prod_dim_nb NUMBER;
    v_usr_dim_nb  NUMBER;
    v_count NUMBER;
    v_product_exception EXCEPTION;
    v_user_exception EXCEPTION;
    p_error_code varchar2(50);
    p_error_msg varchar2(50);
    begin
    for i in  in_pref.first.. in_pref.last
    LOOP
    /* Derive the product and user dim numbers */
    begin
    select prod_dim_nb into  v_prod_dim_nb from prod_dim where prod_cd=in_pref(i).prod_cd ;
    EXCEPTION
        WHEN NO_DATA_FOUND THEN
            p_error_code := sqlcode;
            p_error_msg := SQLERRM;
            raise v_product_exception;
    end;
    BEGIN
    select usr_dim_nb into v_usr_dim_nb from usr_xref where usr_id=in_pref(i).usr_id and sys_id='ACCESS';
    EXCEPTION
        WHEN NO_DATA_FOUND THEN
            p_error_code := sqlcode;
            p_error_msg := SQLERRM ;
            raise v_product_exception;
          raise v_user_exception;
    END;
    /* check if the record already exist in usr_prod_pref corresponding to that  user,prod,pref */
    select count(1) into v_count from usr_prod_pref_test where prod_dim_nb=v_prod_dim_nb and usr_dim_nb=v_usr_dim_nb and pref_cd=in_pref(i).pref_cd;
    if v_count=0 then
    BEGIN
    INSERT INTO USR_PROD_PREF_TEST values(v_usr_dim_nb,in_pref(i).pref_cd,v_prod_dim_nb,in_pref(i).DFLT_PREF_VAL_TX,in_pref(i).usr_PREF_VAL_TX,'Active',NULL,
    in_pref(i).cre_usr_id,sysdate,in_pref(i).updt_usr_id,NULL);
    END;
    else
    update USR_PROD_PREF_TEST set USR_PREF_VAL_TX=in_pref(i).USR_PREF_VAL_TX,DFLT_PREF_VAL_TX=in_pref(i).DFLT_PREF_VAL_TX,UPDT_USR_ID=in_pref(i).updt_usr_id,updt_dt=sysdate,cre_usr_id=in_pref(i).cre_usr_id where
    prod_dim_nb=v_prod_dim_nb and usr_dim_nb=v_usr_dim_nb and pref_cd=in_pref(i).pref_cd;
    end if;
    end loop;
    commit;
    v_status_message:='SUCCESS';
    exception
    when v_product_exception then
    v_status_message:= 'invalid product code  '||p_error_code||p_error_msg;
    when v_user_exception then
    v_status_message:= 'invalid user'||p_error_code||p_error_msg;
    end;
    /Edited by: raj_fresher on Oct 9, 2009 7:33 AM

  • Pass array on to another class

    Hi. Simple question here.
    I have two classes and in one I have an array. I want to pass it on to the other class so I can use the values and stuff there. How do I do that?

    You don't pass things to classes. You pass them to constructors or methods of a class or instance of one.
    If you do this, for example:
    System.out.println("Hello world");
    you are passing a String argument to the println method.
    You can similarly pass your array to a method of some class, if that method accepts an array as a parameter.
    P.S. You're welcome. Obviously you didn't get hit by a bus and couldn't reply with a simple "thank you", as you posted another topic a day or so later than this. But, you're welcome.

  • Pass array to "Labview 7" DLL in Visual Basic

    Hi!
    I would like to pass arrays in Visual Basic to a LV DLL made in Labview 7.
    I've seen the examples of NI to create a dll in Labview for Visual Basic and for passing arrays, but all the examples were made with Labview 6.
    The problem is that in the tutorial they say to define the Pass By of the argument as Array Data Pointer, but in Labview 7 when I add an array as an argument I don't have that option.. It's always defined as TD1Hdl* inArray, and in Labview 6 it was defined as float64 inArray[].
    Can I use the TD1Hdl structure in Visual Basic? How do I use it?
    Thanks!

    Unfortunately, i'm not expert in Visual Basic, i need to investigate in your problem.
    See link below, that explain how you can use LabVIEW DLL in Visual Basic.
    http://venus.ni.com/stage/we/niepd_web_display.DISPLAY_EPD4?p_answer=&p_guid=B45EACE3D9E556A4E034080...
    http://forums.ni.com/ni/board/message?board.id=170&message.id=100151&requireLogin=False
    http://zone.ni.com/devzone/devzoneweb.nsf/Opendoc?openagent&4303F9807BFE234486256906007259EF
    Regards,
    Christophe S.
    FSE East of France І Certified LabVIEW Associate Developer І National Instruments France

  • Arrays? arguments?

    what is the difference between arrays and arguments, and when should either be used.

    An array is a data structure that has a fixed size and allows you to modify and retrieve elements in a random order. In Java, arrays are objects. Use an array when that is the type of data structure you need.
    An argument is a value that is passed to a method or a constructor. In Java, arguments are primitives or references. Use it when you need to pass values to methods.
    Rather than try to understand what an array or an argument is, it's better to simply write some Java code that uses them, and the understanding will come later. How do you write the code before you understand? A book that has exercises that say "write a method that takes two ints and returns their sum" and "write a method that takes a double[] and returns the average value" will help you write the code before you fully understand what you're doing.

  • 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

  • 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 array into resultset

    hi,
    is it possible to pass an array into a resultset? if yes please indicate how.
    thank you all in advance

    Hi,
    Sorry for the confusion, here's what I'm trying to accomplish.
    I'm trying to create a report in Crystal Report and use Java as data source. My Java application needs to generate some value and pass them to the report as parameters. After some research I've found that I can use a Java Bean class as data source for Crystal Report that returns a ResultSet. Therefore I'm trying to pass some values in my Java app into the Bean class as array and convert them to a ResultSet for Crystal Report.
    If you know of a different way please let me know, otherwise, this is what I meant by passing array into resultset.
    thanks for your reply,

  • ORA-00932 when trying to pass ARRAY from Java SP to PL/SQL

    Hi all
    I am trying to pass ARRAYs back and forth between PL/SQL and Java stored procedures. But I keep getting:
    ORA-00932: inconsistent datatypes: expected a return value that is an instance of a user defined Java class convertible to an Oracle type got an object that could not be converted
    Here's my PL/SQL:
    create or replace type CONTENTP.sentences_array as VARRAY(1000) of CLOB
    -- I've also tried .. as TABLE of CLOB and varray/table of VARCHAR2
    declare
    proc_clob CLOB;
    arr SENTENCES_ARRAY;
    begin
    SELECT document_body
    into proc_clob
    from documents
    where document_id = 618784;
    arr := processdocument.sentencesplit (proc_clob);
    end;
    PROCESSDOCUMENT package definition:
    CREATE OR REPLACE PACKAGE CONTENTP.PROCESSDOCUMENT AS
    FUNCTION sentenceSplit(Param1 CLOB)
    return SENTENCES_ARRAY
    AS
    LANGUAGE java
    NAME 'com.contentp.documents.ProcessDocument.sentenceSplit(oracle.sql.CLOB) return oracle.sql.ARRAY';
    FUNCTION removeHTML(Param1 CLOB)
    return CLOB
    AS
    LANGUAGE java
    NAME 'com.contentp.documents.ProcessDocument.removeHTML(oracle.sql.CLOB) return oracle.sql.CLOB';
    end;
    Java sentenceSplit code:
    public static oracle.sql.ARRAY sentenceSplit ( CLOB text) throws IOException, SQLException
    Connection conn = new OracleDriver().defaultConnection();
    String[] arrSentences = sent.getsentences ( CLOBtoString (text) );
    ArrayDescriptor arrayDesc =
    ArrayDescriptor.createDescriptor ("SENTENCES_ARRAY", conn);
    ARRAY ARRSentences = new ARRAY (arrayDesc, conn, arrSentences);
    return ARRSentences;
    I have confirmed that the String[] arrSentences contains a valid string array. So the problem seems to be the creation and passing of ARRSentences.
    I have looked at pages and pages of documents and example code, and can't see anything wrong with my declaration of ARRSentences. I'm at a loss to explain what's wrong.
    Thanks in advance - any help is much appreciated!

    I am trying to do something similar but seems like getting stuck at registerOutParameter for this.
    Type definition:
    CREATE OR REPLACE
    type APL_CCAM9.VARCHARARRAY as table of VARCHAR2(100)
    Java Stored Function code:
    public static ARRAY fetchData (ARRAY originAreaCds, ARRAY serviceCds, ARRAY vvpcs) {
    Connection connection = null;
         ARRAY array = null;
         try {
         connection = new OracleDriver ().defaultConnection();
         connection.setAutoCommit(false);
    ArrayDescriptor adString = ArrayDescriptor.createDescriptor("VARCHARARRAY", connection);
    String[] result = new String [2];
    result[0] = "Foo";
    result[1] = "Foo1";
    array = new ARRAY (adString, connection, result);
    connection.commit ();
    return array;
    } catch (SQLException sqlexp) {
    try {
    connection.rollback();
    } catch (SQLException exp) {
    return array;
    Oracle Stored Function:
    function FETCH_TRADE_DYN_DATA (AREA_CDS IN VARCHARARRAY, SERVICE_CDS IN VARCHARARRAY,VV_CDS IN VARCHARARRAY) return VARCHARARRAY AS LANGUAGE JAVA NAME 'com.apl.ccam.oracle.js.dalc.TDynAllocation.fetchData (oracle.sql.ARRAY, oracle.sql.ARRAY, oracle.sql.ARRAY) return oracle.sql.ARRAY';
    Java Code calling Oracle Stored Procedure:
    ocs = (OracleCallableStatement) oraconn.prepareCall(queryBuf.toString());
                   ArrayDescriptor adString = ArrayDescriptor.createDescriptor("VARCHARARRAY", oraconn);
                   String[] originAreaCds = sTDynAllocationVO.getGeogAreaCds();
                   ARRAY areaCdArray = new ARRAY (adString, oraconn, originAreaCds);
                   ocs.registerOutParameter(1, OracleTypes.ARRAY);
                   ocs.setArray (2, areaCdArray);
                   String[] serviceCds = sTDynAllocationVO.getServiceCds();
                   ARRAY serviceCdsArray = new ARRAY (adString, oraconn, serviceCds );
                   ocs.setArray (3, serviceCdsArray);
                   String[] vvpcs = sTDynAllocationVO.getVesselVoyagePortCdCallNbrs();
                   ARRAY vvpcsArray = new ARRAY (adString, oraconn, vvpcs);
                   ocs.setArray (4, vvpcsArray);
    ocs.execute();
    ARRAY results = ocs.getARRAY(1);
    Error I get:
    Parameter Type Conflict: sqlType=2003
    Thanks for help in advance.

  • URGENT: Passing Array from JSP to a Stored Procedure

    Hi,
    Can some one please help me understanding how can I pass array from JSP page to a stored procedure in database.
    Thanks in advance.
    Jatinder

    Thanks.
    I tried ArrayExampla.java and was successful in passing array values to the stored database procedure.
    How can I use this class in JSP? Like I have first JSP where in I will collect input from the user and then submit it to the second JSP - that needs to call the ArrayExample.java to pass the values as array to the database.
    How should I call this java code in my second JSP?
    Thanks in advance.

  • Pass array to oracle stored procedure

    I have such a problem: I have to pass array to stored procedure, so I declare type:
    create type tNumberArray as table of number
    and create procedure:
    create or replace procedure proc_1 (in_param in tNumberArray) as
    .... BODY OF PROCEDURE ...
    when I call this procedure from C# like this:
    int []pParam = new int[3] {1,2,3};
    OracleCommand cmd = new OracleCommand("proc_1", dbConn);
    cmd.CommandType = CommandType.StoredProcedure;
    OracleParameter param14 = new OracleParameter("param", OracleDbType.Decimal);
    param14.Value = pParam;
    param14.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
    param14.Size = 3;
    param14.Direction = ParameterDirection.Input;
    cmd.Parameters.Add(param14);
    cmd.ExecuteNonQuery();
    an error occures. It say that there invalid number or type of parameters.
    But when I declare both type and procedure in a package everything goes fine.
    What is the matter? Did anybody have the same problem?

    Not I got next problem:
    when I cannot pass parameter to stored procedure and get array fro it. In other words returning array from procedure and passing some input parameters to it does not word!
    Does anybody know why it happens?

  • Passing arrays to methods?

    Hi all,
    Thanks to most of the main contributors in this forum nearly all of my major hurdles in transitioning from proc-C to Cocoa have been overcome. However, while I was shown how to use NSMutableArray in conjunction with NSDictionary to do pretty much the same job as a C-style multi-dimensional array, dictionaries aren't always the perfect solution in every situation. So, let's suppose I wanted to construct a pure Cocoa facsimile of a C-style [4][x] array like this...
    NSArray *replicaArray = [NSArray arrayWithObjects:
    [NSNull null], // index 0 (unused)
    [NSMutableArray array], // index 1
    [NSMutableArray array], // index 2
    [NSMutableArray array],nil]; // index 3
    I threw in an NSNull as the first array object because (whenever possible) I adopted the habit of leaving row0 and column0 of multidimensional arrays unused to make for more natural, readable iteration ops and stuff. The above code works perfectly well, but with 4-5 different arrays in the same proc-C apps I often had to pass them to common functions (to handle things like bubble-sorting etc.) like the one below:
    void bubbleSortSimpleArray (short arry[ ], short numsToSort)
    short ctr,loopCtr,storeValue;
    for (loopCtr = 1; loopCtr <= numsToSort; loopCtr++)
    ctr = 1;
    while (ctr < numsToSort)
    if (arry[ctr] > arry[ctr+1])
    storeValue = arry[ctr+1];
    arry[ctr+1] = arry[ctr];
    arry[ctr] = storeValue;
    ++ctr;
    Of course, thanks to the advantages of Cocoa this entire code block can be replaced in just a couple lines with 'sortUsingSelector'. Sorry for the lengthy outline in attempting to describe my problem as clearly as possible , but (finally) _is it possible to pass arrays to methods_ in our Cocoa code in a similar way? I was thinking something along the lines of:
    - (void)doMoreProcessing:(id)array
    //do some other common stuff on my array(s) here...
    That'd simplify converting some of my old code and be a real bonus for me, but I haven't been able to find any reference about this on the net so far, and experimenting with my code hasn't provided me with any answers yet, either... Any guidance on this would be very much appreciated!
    Thanks in advance.
    Ernie

    Hi Bang A. Lore,
    Thanks for your input but I've got it figured out now However, while you quite correctly say:
    Pointers work the same way as they do in C.
    the cause of my problems wasn't a lack of understanding of pointers, but by the syntax differences between proc-C and obj-C. I'm well aware of the fact that the name of a passed array is just a pointer to its address in memory of course, but attempting to use a mandatory 'C' style header declaration along the lines of:
    - (void)test2DArray:(NSMutableArray*)array[][];
    just kept giving me parse errors, as did any attempt to use square brackets in the implementation file. While 'C' insists on using them, I found (after some more experimentation) that obj-C will quite happily accept:
    - (void)test2DArray:(NSMutableArray*)array;
    ...or the even simpler...
    - (void)test2DArray:(id)array;
    Also pleasantly surprised to find that Cocoa doesn't seem to give a hoot whether the (array) object you pass it is flat OR multidimensional -- whereas 'C' insists you even provide the called function with the number of rows contained in a multi-subscripted array -- which often meant I had to include two versions of many functions containing identical code, depending on whether they were called by 1D or 2D arrays.
    Once I hit on the idea of omitting the square brackets entirely (just to stop the darned parse errors and see what would happen out of curiosity), the problem just went away.
    Thanks once again. Appreciate it!

  • Passing Array of java objects to and from oracle database-Complete Example

    Hi all ,
    I am posting a working example of Passing Array of java objects to and from oracle database . I have struggled a lot to get it working and since finally its working , postinmg it here so that it coudl be helpful to the rest of the folks.
    First thinsg first
    i) Create a Java Value Object which you want to pass .
    create or replace and compile java source named Person as
    import java.sql.*;
    import java.io.*;
    public class Person implements SQLData
    private String sql_type = "PERSON_T";
    public int person_id;
    public String person_name;
    public Person () {}
    public String getSQLTypeName() throws SQLException { return sql_type; }
    public void readSQL(SQLInput stream, String typeName) throws SQLException
    sql_type = typeName;
    person_id = stream.readInt();
    person_name = stream.readString();
    public void writeSQL(SQLOutput stream) throws SQLException
    stream.writeInt (person_id);
    stream.writeString (person_name);
    ii) Once you created a Java class compile this class in sql plus. Just Copy paste and run it in SQL .
    you should see a message called "Java created."
    iii) Now create your object Types
    CREATE TYPE person_t AS OBJECT
    EXTERNAL NAME 'Person' LANGUAGE JAVA
    USING SQLData (
    person_id NUMBER(9) EXTERNAL NAME 'person_id',
    person_name VARCHAR2(30) EXTERNAL NAME 'person_name'
    iv) Now create a table of Objects
    CREATE TYPE person_tab IS TABLE OF person_t;
    v) Now create your procedure . Ensure that you create dummy table called "person_test" for loggiing values.
    create or replace
    procedure give_me_an_array( p_array in person_tab,p_arrayout out person_tab)
    as
    l_person_id Number;
    l_person_name Varchar2(200);
    l_person person_t;
    l_p_arrayout person_tab;
    errm Varchar2(2000);
    begin
         l_p_arrayout := person_tab();
    for i in 1 .. p_array.count
    loop
         l_p_arrayout.extend;
         insert into person_test values(p_array(i).person_id, 'in Record '||p_array(i).person_name);
         l_person_id := p_array(i).person_id;
         l_person_name := p_array(i).person_name;
         l_person := person_t(null,null);
         l_person.person_id := l_person_id + 5;
         l_person.person_name := 'Out Record ' ||l_person_name ;
         l_p_arrayout(i) := l_person;
    end loop;
    p_arrayout := l_p_arrayout;
         l_person_id := p_arrayout.count;
    for i in 1 .. p_arrayout.count
    loop
    insert into person_test values(l_person_id, p_arrayout(i).person_name);
    end loop;
    commit;
    EXCEPTION WHEN OTHERS THEN
         errm := SQLERRM;
         insert into person_test values(-1, errm);
         commit;
    end;
    vi) Now finally create your java class which will invoke the pl/sql procedure and get the updated value array and then display it on your screen>Alternatively you can also check the "person_test" tbale
    import java.util.Date;
    import java.io.*;
    import java.sql.*;
    import oracle.sql.*;
    import oracle.jdbc.driver.*;
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    public class ArrayDemo
    public static void passArray() throws SQLException
    Connection conn = getConnection();
    ArrayDemo a = new ArrayDemo();
    Person pn1 = new Person();
    pn1.person_id = 1;
    pn1.person_name = "SunilKumar";
    Person pn2 = new Person();
    pn2.person_id = 2;
    pn2.person_name = "Superb";
    Person pn3 = new Person();
    pn3.person_id = 31;
    pn3.person_name = "Outstanding";
    Person[] P_arr = {pn1, pn2, pn3};
    Person[] P_arr_out = new Person[3];
    ArrayDescriptor descriptor =
    ArrayDescriptor.createDescriptor( "PERSON_TAB", conn );
    ARRAY array_to_pass =
    new ARRAY( descriptor, conn, P_arr);
    OracleCallableStatement ps =
    (OracleCallableStatement )conn.prepareCall
    ( "begin give_me_an_array(?,?); end;" );
    ps.setARRAY( 1, array_to_pass );
         ps.registerOutParameter( 2, OracleTypes.ARRAY,"PERSON_TAB" );
         ps.execute();
         oracle.sql.ARRAY returnArray = (oracle.sql.ARRAY)ps.getArray(2);
    Object[] personDetails = (Object[]) returnArray.getArray();
    Person person_record = new Person();
    for (int i = 0; i < personDetails.length; i++) {
              person_record = (Person)personDetails;
              System.out.println( "row " + i + " = '" + person_record.person_name +"'" );
                        public static void main (String args[]){
         try
                             ArrayDemo tfc = new ArrayDemo();
                             tfc.passArray();
         catch(Exception e) {
                        e.printStackTrace();
              public static Connection getConnection() {
         try
                             Class.forName ("oracle.jdbc.OracleDriver");
                             return DriverManager.getConnection("jdbc:oracle:thin:@<<HostNanem>>:1523:VIS",
                             "username", "password");
         catch(Exception SQLe) {
                        System.out.println("IN EXCEPTION BLOCK ");
                        return null;
    and thats it. you are done.
    Hope it atleast helps people to get started. Comments are appreciated. I can be reached at ([email protected]) or [email protected]
    Thanks
    Sunil.s

    Hi Sunil,
    I've a similar situation where I'm trying to insert Java objects in db using bulk insert. My issue is with performance for which I've created a new thread.
    http://forum.java.sun.com/thread.jspa?threadID=5270260&tstart=30
    I ran into your code and looked into it. You've used the Person object array and directly passing it to the oracle.sql.ARRAY constructor. Just curios if this works, cos my understanding is that you need to create a oracle.sql.STRUCT out of ur java object collection and pass it to the ARRAY constructor. I tried ur way but got this runtime exception.
    java.sql.SQLException: Fail to convert to internal representation: JavaBulkInsertNew$Option@10bbf9e
                        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
                        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
                        at oracle.jdbc.oracore.OracleTypeADT.toDatum(OracleTypeADT.java:239)
                        at oracle.jdbc.oracore.OracleTypeADT.toDatumArray(OracleTypeADT.java:274)
                        at oracle.jdbc.oracore.OracleTypeUPT.toDatumArray(OracleTypeUPT.java:115)
                        at oracle.sql.ArrayDescriptor.toOracleArray(ArrayDescriptor.java:1314)
                        at oracle.sql.ARRAY.<init>(ARRAY.java:152)
                        at JavaBulkInsertNew.main(JavaBulkInsertNew.java:76)
    Here's a code snippet I used :
    Object optionVal[] =   {optionArr[0]};   // optionArr[0] is an Option object which has three properties
    oracle.sql.ArrayDescriptor empArrayDescriptor = oracle.sql.ArrayDescriptor.createDescriptor("TT_EMP_TEST",conn);
    ARRAY empArray = new ARRAY(empArrayDescriptor,conn,optionVal);If you visit my thread, u'll see that I'm using STRUCT and then pass it to the ARRAY constructor, which works well, except for the performance issue.
    I'll appreciate if you can provide some information.
    Regards,
    Shamik

  • Passing array of Types to java class

    I am trying to pass a user defined type (that is an array) from PL/Sql to a javaclass. Here are the definitions that make-up the parameter to pass from PL/Sql to Java (uri_digest_array):
    CREATE OR REPLACE TYPE uri_digest as object (uri VARCHAR2(256),
    digest_value CLOB);
    CREATE OR REPLACE TYPE uri_digest_array AS VARRAY(10) OF uri_digest;
    In Oracle-land, java classes are published to PL/Sql by way of the following definition. Note that the intent here is to have compatible data-types.
    CREATE OR REPLACE FUNCTION SIGNRETURNINGXML (p_array IN uri_digest_array)
    RETURN LONG
    AS LANGUAGE JAVA
    NAME 'SignReturningXml.main(oracle.sql.Array) return java.lang.String';
    Here is a fragment of the java class code:
    class SignReturningXml {
    public static String main(String [] [] signItems ) // I have no idea what datatype to use here!
    { . . . . The code in here would process the passed array normally from first entry to last.
    Currently I get the following error:
    PLS-00311: the declaration of
    "SignReturningXml.main(oracle.sql.Array) return
    java.lang.String" is incomplete or malformed
    I could use some suggestions on resolving the datatype conflicts. Any ideas? Has anyone tried this kind of thing?
    Thanks,
    Michael

    Michael,
    At the risk of another [non] useful response, I meant that you should try searching the "Ask Tom" Web site, because usually you will find an answer to your question that has already been asked by someone else. Perhaps these will be helpful:
    [url=http://asktom.oracle.com/pls/ask/f?p=4950:8:1320383202207153292::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:8908169959941
    ]Can I Pass a nested table to Java from a pl/sql procedure
    [url=http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:712625135727
    ]passing arrays into pl/sql stored procedures
    Good Luck,
    Avi.

Maybe you are looking for

  • Reinstall CSuite product which is not working after trasferring files from an old Mac to a new one?

    I recently got MacBookPro, and transferred my old laptop files (including apps) to the new one. After trying to open Dreamweaver, I got an error massage. Sent it to, and closed the app thereafter. Than I tried to open the DW again but got a massage a

  • Unable to replace existing default progam setting with group policy preference

    I have a bunch of Windows 8.1 machines on a 2003 domain that we're managing using a 2012 server as a domain controller. I have an OU that contains all the machines and a GPO I've linked to the OU. In the policy, under User Configuration -> Preference

  • Is my external drive using USB 2.0?

    I just hooked up an external USB 2.0 drive. I'm copying my iPhoto library (22 GB) to it. I estimated that using USB 2.0 this should take about 6.5 minutes. Well it has been going for well over an hour and isn't half way done. I used to use this drive

  • INBOUND program  For custom IDOC

    Hi ,       i have a one  senario on creation of IDOC,that is interface for the transmission of the Acknowledgement of check Remittance and Supplemental interface,once the message is received Successfully through OUTBOUND program it triges the Acknowl

  • Ora-01466 unable to read data table definition has changed oracle.

    hi all, i truncated a table before 10 min. now i want the data's so i used this query ; select * from ( select * from sometable where some_condition ) as of timestamp sysdate-1; but it shows: """ ora-01466 unable to read data table definition has cha