shared items

Thursday, October 4, 2012

Call Stored Proc from Java with sql types in Stored Proc Call

        final String typeName = "T_ALL_RECORD";
        final String typeTableName = "T_ALL_RECORDS";

        // Get a description of your type (Oracle specific)
        final StructDescriptor structDescriptor = StructDescriptor.createDescriptor(typeName.toUpperCase(), connection);        
        final ResultSetMetaData metaData = structDescriptor.getMetaData();

        // Call the procedure (or whatever else) that returns the table of a custom type
        CallableStatement cs = connection.prepareCall("{call ult_pkg.get_data_Q1(?, ?)}");
        cs.setString(1, "the_id");
        // Result is an java.sql.Array...
        cs.registerOutParameter(2, Types.ARRAY, typeTableName);     

No comments: