2016-04-21 74 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