Skip to Main Content

Java and JavaScript in the Database

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using arrays as type for bind variable

433977Dec 7 2004 — edited Sep 21 2005
Hi 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 19 2005
Added on Dec 7 2004
4 comments
2,126 views