[英]Not able to call Stored procedure contains Varchar2_table as a parameter from Java
I am trying to write the java code for calling stored procedure using SimpleJdbcCall feature. 我正在尝试编写Java代码以使用SimpleJdbcCall功能调用存储过程。 I am using Oracle 10g, Below is the procedure syntax need to call from our code
我正在使用Oracle 10g,以下是需要从我们的代码中调用的过程语法
Stored Procedure Syntax: 存储过程语法:
CREATE OR REPLACE PROCEDURE ImportFile(
enametab IN VARCHAR2_TABLE,
saltab IN DBMS NUMBER_TABLE)
Stored procedure is accepting the Varchar2.TABLE type and Number_TABLE type, Which is type of Bulk SQL Types. 存储过程接受Varchar2.TABLE类型和Number_TABLE类型,这是Bulk SQL类型的类型。 I have tried below code from java to call the stored procedure.
我已经尝试了以下来自Java的代码来调用存储过程。
Java Code Java代码
SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate)
.withSchemaName("<<schemaName>>")
.withProcedureName("ImportFile")
.declareParameters(new SqlParameter("enametab", Types.ARRAY),
new SqlParameter("saltab", Types.ARRAY));//
// Creating lists
List<String> enameList = new ArrayList<String>();
enameList.add("one");
enameList.add("two");
List<Integer> salList = new ArrayList<Integer>();
salList.add(1);
salList.add(2);
// Converting list into array
String[] enameArray = enameList.toArray(new String[enameList.size()]);
Integer[] salArray = salList.toArray(new Integer[enameList.size()]);
MapSqlParameterSource in = new MapSqlParameterSource();
in.addValue("enametab", enameArray);
in.addValue("sArchiveName", salArray);
// Executing the stored procedure
simpleJdbcCall.execute(in);
After executing the above code I am getting error as 执行上面的代码后,我得到错误
Caused by: java.sql.SQLException: Fail to convert to internal representation:
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.sql.ARRAY.toARRAY(ARRAY.java:238)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:9152)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8739)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:9229)
at oracle.jdbc.driver.OracleCallableStatement.setObject(OracleCallableStatement.java:4691)
at org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:431)
at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:235)
at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:150)
at org.springframework.jdbc.core.CallableStatementCreatorFactory$CallableStatementCreatorImpl.createCallableStatement(CallableStatementCreatorFactory.java:213)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1115)
... 8 more
Any help/suggestions? 任何帮助/建议吗?
You need to use an oracle.sql.ArrayDescriptor
to create an oracle.sql.ARRAY
that holds the data. 您需要使用
oracle.sql.ArrayDescriptor
创建一个保存数据的oracle.sql.ARRAY
。 In the "Spring Data JDBC Extensions" project we handle this in the SqlArrayValue
class. 在“ Spring Data JDBC Extensions”项目中,我们在
SqlArrayValue
类中处理此问题。 You could either implement this functionality yourself or use the convenience classes provided by the "Spring Data JDBC Extensions" project. 您可以自己实现此功能,也可以使用“ Spring Data JDBC Extensions”项目提供的便利类。 See the docs .
请参阅文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.