How can I pass an “array” of values to my stored procedure?

后端 未结 7 744
悲哀的现实
悲哀的现实 2020-12-15 22:39

I want to be able to pass an \"array\" of values to my stored procedure, instead of calling \"Add value\" procedure serially.

Can anyone suggest a way to do it? am I

7条回答
  •  盖世英雄少女心
    2020-12-15 22:55

    Incidently, here is how you would add the array to a function (stored-proc) call:

    CallableStatement proc = null;
    List faultcd_array = Arrays.asList(1003, 1234, 5678);
    //conn - your connection manager
    conn = DriverManager.getConnection(connection string here);
    proc = conn.prepareCall("{ ? = call procedureName(?) }");
    proc.registerOutParameter(1, Types.OTHER);
    //This sets-up the array
    Integer[] dataFaults = faultcd_array.toArray(new Integer[faultcd_array.size()]);
    java.sql.Array sqlFaultsArray = conn.createArrayOf("int4", dataFaults);
    proc.setArray(2, sqlFaultsArray);
    //:
    //add code to retrieve cursor, use the data.
    //:
    

提交回复
热议问题