Using arrays as type for bind variable
433977Dec 7 2004 — edited Sep 21 2005Hi all,
I have this stored procedures that takes an array of strings as an argument:
CREATE OR REPLACE PACKAGE mypackage AS
TYPE StringArray IS VARRAY(100) OF VARCHAR2(16);
...
PROCEDURE doSomething(v_strings IN StringArray);
END;
My java code looks something like:
String[] strings = ...;
CallableStatement cs = connection.prepareCall("CALL mypackage.doSomething(?)");
cs.setObject(1, strings, java.sql.Types.ARRAY);
...
calling the setObject method throws a SQLException: invalid column type.
I have tried to change the call to:
cs.setArray(1, new SqlStringArray(strings))
where SqlStringArray is a wrapper around String[] that implements the java.sql.Array interface. This however throws a ClassCastException in oracle.jdbc.driver.OraclePreparedStatement. The latter is assuming it is receiving a class that implements yet another interface I guess.
I also tried:
cs.setObject(1, strings, java.sql.Types.VARCHAR);
but that also throws a SqlException: invalid conversion requested
Does anybody know how to bind String[] into a PreparedStatement?
Any help is appreciated.
Rudi.