2016-04-21 77 views
0

我已创建的存储过程与ROW类型的数组作为IN参数,并能够使用JDBC(Java的1.6) 代码如下使用SimpleJdbcCall时与数组作为IN参数

//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(); 

任何调用它(DB2)想法如何做到与SimpleJdbcCall一样? 我使用Spring 2.5和DB2 9.7版本

回答

0

我终于明白了。我正在为它粘贴示例代码。

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; 
      } 
     }); 
+0

我究竟做这样的,但得到的异常:com.ibm.db2.jcc.am.SqlFeatureNotSupportedException:[JCC] [T4] [10181] [12052] [4.11'所致。 77]方法createStruct不受支持。 ERRORCODE = -4450,SQLSTATE = 0A504'我正在使用Spring 4.2.2版和DB2 9.7.3版。 – abhishek