描述:尝试创建返回 oracle 数组类型的网关服务调用。特别获取 sys.dbmsoutput_linesarray。下面出现的错误似乎是当我注册 OUT 参数或可能在服务中时我的配置有问题。想知道是否有人可以告诉我我做错了什么?
错误信息:CallableStatementCallback; SQL 的未分类 SQLException [{call GET_DBMS_OUTPUT(?)}]; SQL状态[99999];错误代码[17004];无效的列类型:1111;嵌套异常是 java.sql.SQLException:无效的列类型:1111
我正在尝试在 Spring 集成中执行的参考代码示例:JAVA DBMS ORACLE 数组可调用语句示例 https://github.com/raverkamp/oraclejdbc/blob/master/src/oraclejdbc/DbmsOutput.java
Oracle 12c - PL SQL 函数:
create or replace function get_dbms_output
return dbmsoutput_linesarray
as
l_output dbmsoutput_linesarray;
l_linecount number;
begin
dbms_output.enable;
dbms_output.put_line('This is a line');
dbms_output.put_line('This is another line');
dbms_output.put_line('This is the last line.');
dbms_output.get_lines(l_output, l_linecount);
if l_output.count > l_linecount then
-- Remove the final empty line above l_linecount
l_output.trim;
end if;
return l_output;
end get_dbms_output;
Spring 上下文文件 - 取自 spring 集成 github 示例存储过程 Oracle。使用以下出站网关增强了示例代码。
<bean id="sqlReturnArray" class="org.springframework.data.jdbc.support.oracle.SqlReturnArray"></bean>
<int-jdbc:stored-proc-outbound-gateway
id="outbound-gateway-function-dbms" request-channel="procedureDBMSRequestChannel"
data-source="dataSource"
stored-procedure-name="get_dbms_output"
expect-single-result="true">
<int-jdbc:sql-parameter-definition name="l_output" type="#{T(oracle.jdbc.OracleTypes).ARRAY}" type-name="DBMSOUTPUT_LINESARRAY" direction="OUT" return-type="sqlReturnArray" />
</int-jdbc:stored-proc-outbound-gateway>
JAVA - 更新的字符串转换服务
public interface StringConversionService {
/**
* Converts a String to Upper Case.
*
* @param stringToConvert The string to convert to upper case
* @return The converted upper case string.
*/
String convertToUpperCase(String stringToConvert);
Integer getNumber();
@Payload("new java.util.Date()")
String[] getLines();
}
JAVA-主要
final StringConversionService service = context.getBean(StringConversionService.class);
System.out.println("Calling Stored Proc");
String[] dbmsLines = service.getLines();
更新:
弹簧配置:
- 为 SqlReturnArray 添加了一个 bean。
- 添加了对 SqlReturnArray bean 的引用的返回类型
- 更改 StringConversionService 以使用 String[] 而不是 oracle 数组返回类型。
- 更新主类以获取 String[]