【发布时间】:2018-07-12 07:02:49
【问题描述】:
我是 Spring Boot 开发和 Java 新手。
我在这里尝试借助 simpleJdbcCall.executeFunction 方法从 Spring Boot 调用 Oracle PLSQL 函数。我的 plsql 函数返回单个表行。在 java 中,我试图将函数的结果/输出存储在 Map 数据类型中,但是每当我尝试运行应用程序时,我都会遇到如下所述的错误
PLSQL 函数:
CREATE TABLE test.account1 (
account_id INT,
name VARCHAR2(20)
);
INSERT INTO test.account1 VALUES ( 1, 'Bob' );
INSERT INTO test.account1 VALUES ( 2, 'Nob' );
create or replace function test.get_accounts
(Acc_id in Account1.account_id%Type)
return account1%rowtype
as
l_cust_record account1%rowtype;
begin
select * into l_cust_record from account1
where account_id=Acc_id;
return(l_cust_record);
end;
/
Java 方法:
@SuppressWarnings("unchecked")
public void testFunctionTablerow(){
this.jdbcTemplate =new JdbcTemplate(datasource);
System.out.println("1");
simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate).withFunctionName("get_accounts");
System.out.println("2");
SqlParameterSource in= new MapSqlParameterSource().addValue("Acc_id", 1);
System.out.println("3");
//Map<String, Object> out = simpleJdbcCall.executeFunction(Map.class, in);
Map<String, Object> out= simpleJdbcCall.executeFunction(Map.class, in);
System.out.println(out);
}
错误:
2018-07-12 12:18:34.620 INFO 1560 --- [nio-8000-exec-2] o.s.b.f.xml.XmlBeanDefinitionReader : Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2018-07-12 12:18:34.669 INFO 1560 --- [nio-8000-exec-2] o.s.jdbc.support.SQLErrorCodesFactory : SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]
您能否帮帮我,让我知道当函数返回整行时,在 java 中存储 plsql 函数输出值的正确方法是什么。如果您知道任何其他方法来调用此类返回复杂输出的函数,请分享。
谢谢
【问题讨论】:
-
您的“错误”是两行
INFO日志,与任何错误无关。
标签: java spring plsql spring-data stored-functions