【问题标题】:Error in fetching resultset from oracle PLSQL function in Spring JAVA从 Spring JAVA 中的 oracle PLSQL 函数获取结果集时出错
【发布时间】: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


【解决方案1】:

您可以尝试调用returningResultSet 方法,如下所述:

Calling Oracle procedure that returns rows using SimpleJdbcCall in Spring

【讨论】:

  • 感谢 Andrei 的及时回复,我会尝试这种方法并在此处更新状态。
  • 嗨 Andrei,returningResultSet 方法对我不起作用。我试过了,但我遇到了同样的问题。
  • 如果你得到一个错误,你能发布错误吗?上例中没有错误输出
  • 是的,安德烈。我只得到我在错误中提到的行:在我的问题中。我没有得到任何输出
  • 那我怀疑你没有调用执行函数的代码。我创建了相同的示例,并且在函数调用的日志中出现 PL SQL 错误。什么在您的代码中调用 testFunctionTablerow() 方法?
猜你喜欢
  • 2021-03-26
  • 2018-03-28
  • 1970-01-01
  • 2016-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-04
  • 2010-11-13
  • 1970-01-01
相关资源
最近更新 更多