newbie error on passing in array from java to oracle 11.2 stored procedure
temApr 26 2012 — edited May 4 2012re-posted from JDBC forum (it case it's not related to JDBC):
I'm trying to pass some arrays from Java to an Oracle 11.2 stored procedure. I'm getting the following java compile errors:
********ERRORS**********
myClass.java:343: cannot find symbol
symbol : method setARRAY(int,oracle.sql.ARRAY)
location: interface java.sql.CallableStatement
cs.setARRAY( 1, rla);
^
myClass.java:344: cannot find symbol
symbol : method setARRAY(int,oracle.sql.ARRAY)
location: interface java.sql.CallableStatement
cs.setARRAY( 2, rna);
^
myClass.java:345: cannot find symbol
symbol : method setARRAY(int,oracle.sql.ARRAY)
location: interface java.sql.CallableStatement
cs.setARRAY( 3, cna);
When compiling this code:
********JAVA**********
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import oracle.jdbc.OracleTypes;
import oracle.sql.*;
import oracle.jdbc.driver.*;
public class myClass {
public String SR(String[] rl, String[] rn, int[] cn) throws Exception {
Connection conn;
CallableStatement cs;
Context context = new InitialContext();
DataSource ds = (DataSource)context.lookup("jdbc/dbop");
conn = ds.getConnection();
ArrayDescriptor str_descriptor = ArrayDescriptor.createDescriptor("TYPE_STRING", conn);
ArrayDescriptor num_descriptor = ArrayDescriptor.createDescriptor("TYPE_NUMBER", conn);
ARRAY rla = new ARRAY(str_descriptor, conn, rl);
ARRAY rna = new ARRAY(str_descriptor, conn, rn);
ARRAY cna = new ARRAY(num_descriptor, conn, cn);
cs = conn.prepareCall( "{call myproc (?,?,?)}" );
cs.setARRAY( 1, rla);
cs.setARRAY( 2, rna);
cs.setARRAY( 3, cna);
cs.execute();
if ( conn != null ) {
try { conn.close(); } catch ( Exception ex ) {}
conn = null;
}
}
}
where the database has:
********TYPE**********
create or replace TYPE type_number AS table OF NUMBER(2,0);
create or replace TYPE type_string AS table OF VARCHAR2(150);
and
********STORED PROCEDURE**********
create or replace procedure myproc (
in_rla IN type_string,
in_rna IN type_string,
in_cna IN type_number)
as
begin
FOR ii IN 1.. 7
LOOP
INSERT INTO mytable (col_cn, col_rn, col_rl)
VALUES (in_cna(ii), in_rna(ii), in_rla(ii));
END LOOP;
COMMIT;
END myproc;
The documentation shows setARRAY should be available:
http://docs.oracle.com/cd/E18283_01/appdev.112/e13995/oracle/jdbc/OracleCallableStatement.html#setARRAY_java_lang_String__oracle_sql_ARRAY_
I've been trying to follow these directions:
http://www.stanford.edu/dept/itss/docs/oracle/10g/java.101/b10979/oraarr.htm#i1058512
If I replace setARRAY with setArray, it compiles fine but produces a runtime error. If it's possible to use setArray, do you see anything else wrong? It's my first attempt at passing in arrays from java to stored procedure.