Några små ändringar från din kod - med oracle.sql.ARRAY
snarare än java.sql.Array
och sedan använda OracleConnection.setARRAYAtName()
snarare än Connection.setObject()
för att binda parametern.
(Obs:detta fungerade med Oracle Driver ojdbc6.jar med Oracle 11.2.0.1)
Oracle-inställningar;
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 ){}
}
}
}