title: Java: Send array to a PL-SQL function
body: <p>I need to pass an array of objects to a PL-SQL function</p>
  
  <p>My ORACLE code:</p>
  
  <pre><code>CREATE OR REPLACE
  TYPE
          uu.ITEMTAB AS TABLE OF ITEMREC; 
  /
  
  CREATE OR REPLACE
  TYPE
          uu.ITEMREC AS OBJECT (ID NUMBER,
                                 NAME VARCHAR2(30)) 
  /
  </code></pre>
  
  <p>Java class</p>
  
  <pre><code>public class ITEMREC {
  
      private int ID;
      private String NAME;
  
      public ITEMREC(int iD, String nAME) {
          super();
          ID = iD;
          NAME = nAME;
      }
      public int getID() {
          return ID;
      }
      public void setID(int iD) {
          ID = iD;
      }
      public String getNAME() {
          return NAME;
      }
      public void setNAME(String nAME) {
          NAME = nAME;
      }
  }
  </code></pre>
  
  <p>Java code:</p>
  
  <pre><code>import java.sql.CallableStatement;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  import java.sql.Types;
  
  import oracle.sql.ARRAY;
  import oracle.sql.ArrayDescriptor;
  
  public class Testna {
  
      public static void main(String args[]) throws java.io.IOException, SQLException, ClassNotFoundException
      {
  
          ITEMREC[] myA = new ITEMREC[1];
          myA[0] = new ITEMREC(1, "BOB");
  
          Class.forName("oracle.jdbc.driver.OracleDriver");
          Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL","uu","uu");
  
          ArrayDescriptor desc= ArrayDescriptor.createDescriptor("ITEMTAB", con);  
          ARRAY array = new ARRAY(desc, con, myA);
  
          System.out.println("Connection created..............");
          String call = "{ ? = call mainpackage.fgetText(?) }";
          CallableStatement cstmt = con.prepareCall(call);
          cstmt.setQueryTimeout(1800);
          cstmt.registerOutParameter(1, Types.VARCHAR);
          cstmt.setArray(2, array);
          cstmt.executeUpdate();
          String val = cstmt.getString(1);
          cstmt.close();
          con.close();
          System.out.println(val);
      }   
  }
  </code></pre>
  
  <p>Note: here I have only one object, as this is just for test.</p>
  
  <p>The new error I get is at:</p>
  
  <pre><code>ARRAY array = new ARRAY(desc, con, myA);
  
  Exception in thread "main" java.sql.SQLException: Fail to convert to internal representation:
  </code></pre>
  
  <p>UPDATED:
  I have updated my code,</p>
  
  <p>Thanx @Codo</p>