Par*_*ras 6 spring jdbctemplate jboss7.x
我需要将一个数组Object传递给Oracle 11 DB.我正在使用基于注释Spring 3.1并SimpleJdbcCall用于在JBOSS服务器上调用该过程.这是相关的jdbcCall.
SimpleJdbcCall call = new SimpleJdbcCall(dataSource)
.withoutProcedureColumnMetaDataAccess()
.withProcedureName(IbeginDataBaseConstants.PROCEDURE_CREATE_NEW_ADMIN.VAL)
.declareParameters(new SqlParameter("inUserEmpID", OracleTypes.INTEGER))
.declareParameters(new SqlParameter("inCountryIDs", OracleTypes.ARRAY, "ibo_number_array" ))
.declareParameters(new SqlParameter("inSysRoleID", OracleTypes.INTEGER))
.declareParameters(new SqlParameter("inLoggedIn", OracleTypes.INTEGER))
.declareParameters(new SqlOutParameter("outStatus", OracleTypes.CHAR))
.declareParameters(new SqlOutParameter("outMsg", OracleTypes.VARCHAR));
Run Code Online (Sandbox Code Playgroud)
正如您所看到inCountryIDs的,我需要发送一个数组.
在谷歌的帮助下,我能够通过多种方式将Array发送到DB.这是第一个.
SqlTypeValue value = new AbstractSqlTypeValue() {
protected Object createTypeValue(Connection conn, int sqlType, String typeName) throws SQLException {
ArrayDescriptor arrayDescriptor = new ArrayDescriptor(typeName, conn);
ARRAY idArray = new ARRAY(arrayDescriptor, conn, ids);
return idArray;
}
Run Code Online (Sandbox Code Playgroud)
我把它添加到参数源使用
sourceMap.addValue("inUserEmpID", newAdmin.getEmpId());
sourceMap.addValue("inCountryIDs", value);
sourceMap.addValue("inSysRoleID", newAdmin.getRoleId());
sourceMap.addValue("inLoggedIn", newAdmin.getLoggedInId());
Run Code Online (Sandbox Code Playgroud)
我得到的例外是
org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast to oracle.jdbc.OracleConnection
我明白了原因,SqlTypeValue实现需要OracleConnection,而Spring则传递WrappedConnection.
因此,我尝试使用WrappedConnection此代码使用类解包连接.
WrappedConnection wrappedConnection = conn.unwrap(WrappedConnection.class);
Run Code Online (Sandbox Code Playgroud)
但这里有例外
Not a wrapper for: org.jboss.jca.adapters.jdbc.WrappedConnection
Run Code Online (Sandbox Code Playgroud)
在另一次尝试中,我尝试使用显式强制转换将现有连接强制转换为WrappedConnection.
WrappedConnection wrappedConn = (WrappedConnection)conn;
Run Code Online (Sandbox Code Playgroud)
但仍然没有运气.例外.
org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast to org.jboss.jca.adapters.jdbc.WrappedConnection
Run Code Online (Sandbox Code Playgroud)
好吧,我所要做的就是检索底层连接,所以我试着把它投入,WrappedConnectionJDK6以便我可以在那里调用相关方法.
WrappedConnectionJDK6 wrappedConnection = (WrappedConnectionJDK6)conn;
Run Code Online (Sandbox Code Playgroud)
导致org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6无法强制转换为org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6
第二种方法
Map in = Collections.singletonMap("inCountryIDs", new SqlArrayValue(idsArray));
Run Code Online (Sandbox Code Playgroud)
这种方法的问题是Collections.singletonMap返回一个不可变的映射.所以,我不能用它来添加更多参数.
有什么办法可以在JBoss Wrapped Connection中检索底层连接吗?或者是否有任何其他机制可以通过它传递数组参数而无需与连接进行交互?
| 归档时间: |
|
| 查看次数: |
784 次 |
| 最近记录: |