简体   繁体   English

如何将Java对象列表传递给oracle存储过程(不能使用Spring)

[英]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.

相关问题 如何将 List&lt;&gt; 传递给 Oracle 存储过程 - How to pass a List<> to an Oracle stored procedure 将List of Bean传递给oracle存储过程的Java程序 - 一次传递整个列表而不是一个接一个地追加对象 - Java program to pass List of Bean to a oracle stored procedure - Pass entire list at one shot rather than appending objects one after the other 如何使用休眠本机SQL查询将对象列表传递给oracle中的存储过程 - How to pass a list of objects to a stored procedure in oracle using hibernate native sql query 如何将列表从 Java 传递到 Oracle 过程? - How to pass List from java to Oracle Procedure? 无法将数组传递给Oracle中的存储过程 - Cannot pass array to stored procedure in oracle 如何使用以下详细信息将java对象传递给oracle存储过程 - how to pass a java object to oracle stored procedure with following details 将oracle对象类型传递给j​​ava存储过程 - Pass oracle object type to java stored procedure 如何将BLOB数组传递给存储的oracle过程? - How to pass an array of BLOB to a stored oracle procedure? 如何并行执行oracle java存储过程 - How to execute oracle java stored procedure in parallel 使用 JdbcTemplate 将 Java 数组传递给 ORACLE 存储过程 - Pass an Java Array to ORACLE Stored Procedure using JdbcTemplate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM