Einige kleine Änderungen an Ihrem Code - mit oracle.sql.ARRAY
statt java.sql.Array
und dann mit OracleConnection.setARRAYAtName()
statt Connection.setObject()
um den Parameter zu binden.
(Hinweis:Dies funktionierte mit dem Oracle-Treiber ojdbc6.jar mit Oracle 11.2.0.1)
Oracle-Setup;
CREATE TYPE rec_type AS OBJECT( id NUMBER, descr VARCHAR2(100) );
/
CREATE TYPE tab_type AS TABLE OF rec_type;
/
CREATE TABLE bom OF rec_type;
/
CREATE PROCEDURE pBom( t IN tab_type )
IS
BEGIN
FORALL i IN INDICES OF t
INSERT INTO bom VALUES t(i);
END;
/
Java :
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import oracle.jdbc.OracleCallableStatement;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
public class TestDatabase2 {
public static void main(String args[]){
Connection con = null;
try{
Class.forName("oracle.jdbc.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:XE",
"username",
"password"
);
ArrayDescriptor des = ArrayDescriptor.createDescriptor("TAB_TYPE", con);
Object[] o1 = { 1, "ABC" };
Object[] o2 = { 3, "DEF" };
Object[] o3 = { 2, "GHI" };
ARRAY objs = new ARRAY( des, con, new Object[][]{ o1, o2, o3 } );
CallableStatement st = con.prepareCall("{ call pBOM( :arr )}");
((OracleCallableStatement) st).setARRAYAtName( "arr", objs );
st.execute();
} catch(ClassNotFoundException | SQLException e) {
System.out.println(e);
} finally {
try {
if ( con != null )
{
con.close();
}
} catch ( SQLException e ){}
}
}
}