Java 使用Spring调用Oracle存储过程';s org.springframework.jdbc.object.storedProcess

Java 使用Spring调用Oracle存储过程';s org.springframework.jdbc.object.storedProcess,java,spring,oracle,jdbc,spring-jdbc,Java,Spring,Oracle,Jdbc,Spring Jdbc,我正在开发应用程序(SpringFramework 2.5-旧版)。任务是使用“org.springframework.jdbc.object.StoredProcedure”调用oracle的存储过程 奇怪的是——它编译、执行、不抛出错误——并返回null而不是实际值 我的测试程序(在一个包中)如下所示: procedure testprocedure(varchar2中的input1, 在varchar2中输入2, 输出1输出VARCHAR2, 输出2输出VARCHAR2) 是 开始 out

我正在开发应用程序(SpringFramework 2.5-旧版)。任务是使用“org.springframework.jdbc.object.StoredProcedure”调用oracle的存储过程

奇怪的是——它编译、执行、不抛出错误——并返回null而不是实际值

我的测试程序(在一个包中)如下所示:

procedure testprocedure(varchar2中的input1,
在varchar2中输入2,
输出1输出VARCHAR2,
输出2输出VARCHAR2)
是
开始
output1:=“return1”;
output2:=“return2”;
结束测试程序;
Java代码是:

public class TestClass extends StoredProcedure {
public static final String input1 = "input1";
public static final String input2 = "input2";
public static final String output1 = "output1";
public static final String output2 = "output2";

public TestClass() {
    setSql("testpackage.testprocedure");
    setFunction(false);
    declareParameter(new SqlOutParameter(output1, Types.VARCHAR));
    declareParameter(new SqlOutParameter(output2, Types.VARCHAR));
    declareParameter(new SqlParameter(input1, Types.VARCHAR));
    declareParameter(new SqlParameter(input2, Types.VARCHAR));
}

public TestReturn getTestProcedureOUTs (String pinput1, String pinput2) {
    Map<String, Object> in = new HashMap<String, Object>();
    in.put( input1, pinput1);
    in.put( input2, pinput2);

    System.out.println("Calling " + getSql() + " with parameters: " + in);

    Map<String, Object> res = execute(in);
    System.out.println("output is " + res);
    return new TestReturn((String) res.get(output1), (String) res.get(output2));

}}
我怀疑这与windows版本(windows 10)有关 java版本(1.7) Oracle驱动程序(ojdbc6.jar)


或者别的什么-我自己看清楚。

声明参数的顺序很重要

参数的声明顺序应与它们在oracle过程或函数中出现的顺序相同

在我的例子中,我必须在类构造函数中对这些参数声明重新排序,并将它们如下所示:

public TestClass()    {
    setSql("testpackage.testprocedure");
    setFunction(false);
    declareParameter(new SqlParameter(input1, Types.VARCHAR));
    declareParameter(new SqlParameter(input2, Types.VARCHAR));
    declareParameter(new SqlOutParameter(output1, Types.VARCHAR));
    declareParameter(new SqlOutParameter(output2, Types.VARCHAR));
}
spring框架参考中描述了此行为:


我们已经知道答案了,但是现在就不知道了,以防有人喜欢这样的测验。这里的提示是“其他的东西-显而易见”,如果你知道答案,那么你应该把它作为一个答案发布,它可能会帮助其他人。没有什么比为一个问题去谷歌更令人沮丧的了,去问一个没有答案的问题,但是他只做了一个评论,没有进一步的细节。我很抱歉。谢谢你的评论。说得好。
public TestClass()    {
    setSql("testpackage.testprocedure");
    setFunction(false);
    declareParameter(new SqlParameter(input1, Types.VARCHAR));
    declareParameter(new SqlParameter(input2, Types.VARCHAR));
    declareParameter(new SqlOutParameter(output1, Types.VARCHAR));
    declareParameter(new SqlOutParameter(output2, Types.VARCHAR));
}