Array传入存储过程的示例
Oracle中把Array类型作为参数传入存储过程并用Java对其进行调用的示例是本文我们主要要介绍的内容,接下来我们就开始介绍这一过程。 create or replace procedure test1(arr in varchar_array) isbeginFOR i IN arr.firstarr.last LOOPinsert into tb values(arr(i));
END LOOP;end test1;
String driver = "oracle.jdbc.driver.OracleDriver";
String strUrl = "jdbc:oracle:thin:@192.168.1.199:1521:orcl";
Statement stmt = null;ResultSet rs = null;
Connection conn = null; try {Class.forName(driver);
conn = DriverManager.getConnection(strUrl, "user", "pass");
CallableStatement proc = null;
proc = conn.prepareCall("{ call test1(?) }");
//调用存储过程test1//不一样的地方,获得上面创建的自定义的类型,注意大小写
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("VARCHAR_ARRAY", conn);
List list = new ArrayList();list.add("a");
list.add("b");中华考试网
//把list中的元素转换成自定义的类型ARRAY array = new ARRAY(descriptor, conn, list.toArray());
proc.setArray(1, array); proc.execute();
catch (Exception ex) {ex.printStackTrace();
} finally {…… 各种 close ……}
页:
[1]