java .sql.SQLException:

I am trying to pass an oracle array into a java function using oracle.sql.ARRAY .I m passing this data using a PL/SQL procedure for calling java function (in oracle)(java in oracle).Whenever I try to do this I get the following exception for array datatype:-

java.sql.SQLException:Fail to convert into internal representation: invalid data conversion.

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)

at oracle.jdbc.dbaccess.DBError.check_error(DBError.java)

at oracle.sql.SQLUtil.SQLToJava(SQLUtil.java)

at oracle.sql.SQLUtil.SQLToJava(SQLUtil.java)

at oracle.jdbc.kprb.Conversions.makeOne(Conversions.java)

My java code is:package test.inside;

import oracle.sql.*;

import java.sql.SQLException;

public class ArrayTest

{

public static void fun_array(oracle.sql.ARRAY a) throws SQLException

{

try

{

System.out.println("String is"+a);

String [] sa = (String[]) a.getArray();

String s = new String();

for (int i = 0; i < sa.length; i++)

{

s = s.concat(sa);

}

System.out.println("String is"+s);

}catch (SQLException e) {System.err.println(e.getMessage());}

}

public static void fun(oracle.sql.CHAR c ) throws SQLException

{

System.out.println("Character is " + c);

}

public static void main(String s[])

{

ArrayTest at = new ArrayTest();

}

}

My PL/SQL package for invoking java is:CREATE OR REPLACE PACKAGE "ARRAYTEST" AS

PROCEDURE fun(Param1 VARCHAR2)

AS

LANGUAGE java

NAME 'test.inside.ArrayTest.fun(oracle.sql.CHAR)';

PROCEDURE fun_array(Param1 test_varray)

AS

LANGUAGE java

NAME 'test.inside.ArrayTest.fun_array(oracle.sql.ARRAY)';

PROCEDURE main(Param1 VARCHAR2)

AS

LANGUAGE java

NAME 'test.inside.ArrayTest.main(java.lang.String[])';

end;

I m passing test_varray which is a varray of varchar2 to java function as follows:declare

a test_varray:= test_varray('anvcb','bnvb','cyrwy');

begin

dbms_java.set_output(1000);

ArrayTest.fun('niha');

ArrayTest.fun_array(a);

end;

Please tell me why I m getting exception when I m trying to pass an array .

[2416 byte] By [Niharikaa] at [2007-10-2 7:55:23]
# 1
I'm afraid it isn't supported. I could be wrong, maybe depends on what version of Oracle & driver. Have you checked out the JDBC data types mappings: http://e-docs.bea.com/liquiddata/docs10/querybld/appb.html#1015609
SoulTech2012a at 2007-7-16 21:44:59 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
Is your code supporteb by the API jdbc driver type ? I think that you must to be sure that your driver provides that functional behavior. In my opinion arrays is an special case .
Miguel231152a at 2007-7-16 21:44:59 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3
i am afraid have insatalled oracle- jdbc driver to run the code and make connection from java to oracle.
centurionsa at 2007-7-16 21:44:59 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4

Hi,

I've read the postings above because I tried to do something similar to that what Niharika posted, e.g. implement a java function where you can pass an "SQL array" (TABLE or VARRAY) as input and access it's values.

My question: Am I right that this is not possible? I can't imagine this!

In my programm I can use the methods ARRAY.length() and ARRAY.getBaseTypeName(), so in principal it seems to work because. But when I try to access the values of the Array (of user-defined type) this leads to an error:

java.lang.ClassCastException.

Here's an example (it's similar to Niharika's code):

public static void fun_array(oracle.sql.ARRAY a)

throws SQLException{

String str = a.length();// this works

String str = a.getBaseTypeName();// this works, too

MyType[] sa = (MyType[]) a.getArray(); // => exception?!

...}

Any ideas, hints, working examples?

I would be very thankful for every answer.

stuuffa at 2007-7-16 21:44:59 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...