使用带有数组作为 IN 参数的 SimpleJdbcCall (DB2)
Using SimpleJdbcCall with Array as IN parameter (DB2)
我创建了一个将 ROW 类型的数组作为 IN 参数的存储过程,并且能够使用 JDBC (Java 1.6) 调用它
代码如下
//Create Array Product List
Struct[] productList = new Struct[1];
Object[] customObject = new Object[]{"Fruits"};
productList[0] = con.createStruct("ProductRow", customObject);
// Create product Response List
Struct[] responseList = new Struct[1];
customObject = new Object[]{new Integer(1), new Integer(2)};
responseList[0] = con.createStruct("ResponseRow", customObject);
Array products = con.createArrayOf("ProductRow", productList);
Array responses = con.createArrayOf("ResponseRow", responseList);
// Prepare the call statement
CallableStatement callStmt = con.prepareCall("CALL SP_create(?, ?)");
// Set IN parameters
callStmt.setArray(1, products);
callStmt.setArray(2, responses);
// Call the procedure
callStmt.execute();
知道如何使用 SimpleJdbcCall 做同样的事情吗?
我正在使用 Spring 2.5 和 DB2 9.7 版本
我终于明白了。我正在为它粘贴示例代码。
Map<String, Object> in = new HashMap<String, Object>();
in.put("products", new AbstractSqlTypeValue() {
@Override
protected Object createTypeValue(Connection con, int type, String typeName) throws SQLException {
Struct[] productList = new Struct[1];
Object[] customObject = new Object[]{"Vegetables"};
productList[0] = con.createStruct("ProductRow", customObject);
Array products = con.createArrayOf("ProductRow", productList);
return products;
}
});
我创建了一个将 ROW 类型的数组作为 IN 参数的存储过程,并且能够使用 JDBC (Java 1.6) 调用它 代码如下
//Create Array Product List
Struct[] productList = new Struct[1];
Object[] customObject = new Object[]{"Fruits"};
productList[0] = con.createStruct("ProductRow", customObject);
// Create product Response List
Struct[] responseList = new Struct[1];
customObject = new Object[]{new Integer(1), new Integer(2)};
responseList[0] = con.createStruct("ResponseRow", customObject);
Array products = con.createArrayOf("ProductRow", productList);
Array responses = con.createArrayOf("ResponseRow", responseList);
// Prepare the call statement
CallableStatement callStmt = con.prepareCall("CALL SP_create(?, ?)");
// Set IN parameters
callStmt.setArray(1, products);
callStmt.setArray(2, responses);
// Call the procedure
callStmt.execute();
知道如何使用 SimpleJdbcCall 做同样的事情吗? 我正在使用 Spring 2.5 和 DB2 9.7 版本
我终于明白了。我正在为它粘贴示例代码。
Map<String, Object> in = new HashMap<String, Object>();
in.put("products", new AbstractSqlTypeValue() {
@Override
protected Object createTypeValue(Connection con, int type, String typeName) throws SQLException {
Struct[] productList = new Struct[1];
Object[] customObject = new Object[]{"Vegetables"};
productList[0] = con.createStruct("ProductRow", customObject);
Array products = con.createArrayOf("ProductRow", productList);
return products;
}
});