Některé malé změny ve vašem kódu – pomocí oracle.sql.ARRAY
spíše než java.sql.Array
a poté pomocí OracleConnection.setARRAYAtName()
spíše než Connection.setObject()
svázat parametr.
(Poznámka:toto fungovalo pomocí ovladače Oracle ojdbc6.jar s Oracle 11.2.0.1)
Nastavení Oracle;
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 ){}
}
}
}