title: How to create an oracle.sql.ARRAY object?
body: <p>This question is related to my original issue <a href="https://stackoverflow.com/q/7872688">How to return an array from Java to PL/SQL ?</a>, but is a more specific.</p>
  
  <p>I have been reading <a href="http://download.oracle.com/docs/cd/E11882_01/java.112/e16548/toc.htm" rel="nofollow noreferrer">Oracle Database JDBC Developer's Guide</a> and</p>
  
  <ul>
  <li><a href="http://download.oracle.com/docs/cd/E11882_01/java.112/e16548/oraarr.htm#i1056647" rel="nofollow noreferrer">Creating ARRAY objects</a></li>
  <li><a href="http://download.oracle.com/docs/cd/E11882_01/java.112/e16548/ssid.htm" rel="nofollow noreferrer">Server-Side Internal Driver</a></li>
  <li><a href="http://download.oracle.com/docs/cd/E11882_01/appdev.112/e13995/oracle/jdbc/OracleConnection.html" rel="nofollow noreferrer">oracle.jdbc.OracleConnection</a></li>
  <li><a href="http://download.oracle.com/docs/cd/E11882_01/appdev.112/e13995/oracle/jdbc/OracleDriver.html" rel="nofollow noreferrer">oracle.jdbc.OracleDriver</a></li>
  </ul>
  
  <p>but I still fail to write a minimum code where I can create ARRAY using </p>
  
  <pre><code>ARRAY array = oracle.jdbc.OracleConnection.createARRAY(sql_type_name, elements);
  </code></pre>
  
  <p>as instructed in <a href="http://download.oracle.com/docs/cd/E11882_01/java.112/e16548/oraarr.htm#i1056647" rel="nofollow noreferrer">Creating ARRAY objects</a>.</p>
  
  <p>I'm using Oracle Database JVM.</p>
  
  <p>I have tried following:</p>
  
  <p><strong>Example 1</strong></p>
  
  <pre><code>create or replace type widgets_t is table of varchar2(32767);
  /
  
  create or replace and compile java source named "so20j1" as
  public class so20j1 {
      public void f1() {
          String[] elements = new String[]{"foo", "bar", "zoo"};
          oracle.sql.ARRAY widgets =
              oracle.jdbc.OracleConnection.createARRAY("widgets_t", elements);
      }
  };
  /
  show errors java source "so20j1"
  </code></pre>
  
  <p>Fails with:</p>
  
  <pre><code>Errors for JAVA SOURCE "so20j1":
  
  LINE/COL ERROR
  -------- -----------------------------------------------------------------
  0/0  so20j1:4: non-static method
       createARRAY(java.lang.String,java.lang.Object) cannot be
       referenced from a static context
  
  0/0  1 error
  0/0  ^
  0/0  oracle.sql.ARRAY widgets =
       oracle.jdbc.OracleConnection.createARRAY("widgets_t", elements);
  </code></pre>
  
  <p><strong>Example 2</strong></p>
  
  <pre><code>create or replace type widgets_t is table of varchar2(32767);
  /
  
  create or replace and compile java source named "so20j2" as
  
  public class so20j2 {
      public void f1() {
          String[] elements = new String[]{"foo", "bar", "zoo"};
          oracle.jdbc.OracleDriver ora = new oracle.jdbc.OracleDriver();
          java.sql.Connection conn = ora.defaultConnection();
          oracle.sql.ARRAY widgets = conn.createARRAY("widgets_t", elements);
      }
  };
  /
  show errors java source "so20j2"
  </code></pre>
  
  <p>Fails with:</p>
  
  <pre><code>Errors for JAVA SOURCE "so20j2":
  
  LINE/COL ERROR
  -------- -----------------------------------------------------------------
  0/0  so20j2:6: cannot find symbol
  0/0  symbol  : method createARRAY(java.lang.String,java.lang.String[])
  0/0  1 error
  0/0  oracle.sql.ARRAY widgets = conn.createARRAY("widgets_t",
       elements);
  
  0/0  ^
  0/0  location: interface java.sql.Connection
  </code></pre>
  
  <p>Disclaimer: I'm not a Java programmer (yet).</p>