[英]How to pass java list of objects to oracle stored procedure (Cannot use Spring)
I have a list of POJO's that I want to pass to an Oracle Stored Procedure and then loop through that list in the stored proc and run update statements 我有一个要传递给Oracle存储过程的POJO列表,然后在存储的proc中遍历该列表并运行update语句
I've tried using a StructDescriptor but I keep getting an exception due to my connection object 我尝试使用StructDescriptor,但由于我的连接对象而不断收到异常
(java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast to oracle.jdbc.OracleConnection)
public void MyMethod(List<myObject> myObjectList) {
private Connection con = null;
private CallableStatement stmt = null;
try {
con = getConnection();
String query = "{call "+getStoredProcedureName()+"(?)}";
stmt.setArray(1, myObjectList);
stmt = con.prepareCall(query);
stmt.execute();
} catch(Exception e) {
throw e;
}
}
In Oracle 在甲骨文
create or replace TYPE "MY_REC" AS OBJECT
(
field_one varchar2(50),
field_two varchar2(100)
);
create or replace TYPE "MY_REC_T" AS TABLE OF MY_REC;
I expect myObjectList to be passed to my stored procedure 我希望将myObjectList传递给我的存储过程
Working with other connection wrappers (not jboss), I have had to unwrap the connection to get the underlying OracleConnection
: 与其他连接包装程序(不是jboss)一起使用,我不得不拆开连接以获取基础的
OracleConnection
:
Connection connection = getConnection();
if ( !connection.isWrapperFor( OracleConnection.class ) )
{
// throw exception
}
OracleConnection oConnection = (OracleConnection) connection.unwrap( OracleConnection.class );
The JBoss documentation and this answer also suggests that you could use: JBoss文档和此答案还建议您可以使用:
WrappedConnection wrapped = (WrappedConnection) getConnection();
OracleConnection oConnection = (OracleConnection) wrapped.getUnderlyingConnection();
After that, there are multiple other answers on how to pass a Java array to Oracle SQL [1] [2] [3] 此后,还有关于如何将Java数组传递给Oracle SQL的其他多个答案[1] [2] [3]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.