问题
Description: Attempting to create a gateway service call that returns a oracle array type. Specially getting the sys.dbmsoutput_linesarray. The error I get below seems that I have something wrong on my configuration when I register the OUT param or possibly in the service. Wondering if someone can tell me what I am doing wrong?
Error Message: CallableStatementCallback; uncategorized SQLException for SQL [{call GET_DBMS_OUTPUT(?)}]; SQL state [99999]; error code [17004]; Invalid column type: 1111; nested exception is java.sql.SQLException: Invalid column type: 1111
Referenced Code Example I am trying to do in spring integration: JAVA DBMS ORACLE ARRAY CALLABLE STATEMENT EXAMPLE
Oracle 12c - PL SQL Function:
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 Context File - Taken from spring integration git hub example stored-procedure-oracle . Sample code was augmented with the following outbound gateway.
<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 - Updated String Conversion Service
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 - MAIN
final StringConversionService service = context.getBean(StringConversionService.class);
System.out.println("Calling Stored Proc");
String[] dbmsLines = service.getLines();
Updated: Spring Config: - Added a bean for SqlReturnArray. - Added a return-type for a reference to SqlReturnArray bean - Change the StringConversionService to use a String[] instead of oracle Array return type. - Updated main class to get String[]
回答1:
You have to add return-type and implement it somehow like SqlReturnArray:
<int-jdbc:sql-parameter-definition name="l_output" type="#{T(oracle.jdbc.OracleTypes).ARRAY}" type-name="DBMSOUTPUT_LINESARRAY" direction="OUT" return-type="sqlReturnArray" />
Where sqlReturnArray is a bean of that SqlReturnArray.
And of course, handle the result as a String[] already, not a unavailable there ARRAY.
来源:https://stackoverflow.com/questions/42324142/spring-integration-failing-to-retrieve-oracle-array-out-param