From the document of postgresql i found that :
从postgresql的文档我发现:
con.setAutoCommit(false);
Procedure call.
CallableStatement proc = con.prepareCall("{ ? = call doquery ( ? ) }");
proc.registerOutParameter(1, Types.Other);
proc.setInt(2, -1);
proc.execute();
ResultSet results = (ResultSet) proc.getObject(1);
refer here
While, I tried to create a procedure just like
虽然,我试图创建一个程序就像
CREATE OR REPLACE FUNCTION PSSQLPRC(pA IN VARCHAR,pB IN NUMERIC,PC OUT NUMERIC)
RETURNS NUMERIC
AS $$<br> begin
... ...
end;
$$ Language PLPGSQL;
Using java to call the postgresql procedure likes below
使用java调用postgresql过程,如下所示
CallableStatement proc = con.prepareCall("{ ? = call PSSQLPRC(?,?,?) }");
proc.registerOutParameter(1, Types.NUMERIC);
proc.setString(2,"abc");
proc.setInt(3,10);
proc.registerOutParameter(4, Types.NUMERIC);
proc.execute();
when the CallableStatement's object to exectue , error will occur. What can i do resolve the error? Are statements above correct?
当CallableStatement的对象exectue时,将发生错误。我该怎么办才能解决错误?上述陈述是否正确?
1 个解决方案
#1
0
Do you really need 2 return values from your stored procedure? If not, try changing the function to:
你真的需要从存储过程中获得2个返回值吗?如果没有,请尝试将功能更改为:
CREATE OR REPLACE FUNCTION PSSQLPRC(pA IN VARCHAR,pB IN NUMERIC)
RETURNS NUMERIC
And the Java code:
和Java代码:
CallableStatement proc = con.prepareCall("{ ? = call PSSQLPRC(?,?) }");
proc.registerOutParameter(1, Types.NUMERIC);
proc.setString(2,"abc");
proc.setInt(3,10);
proc.execute();
#1
0
Do you really need 2 return values from your stored procedure? If not, try changing the function to:
你真的需要从存储过程中获得2个返回值吗?如果没有,请尝试将功能更改为:
CREATE OR REPLACE FUNCTION PSSQLPRC(pA IN VARCHAR,pB IN NUMERIC)
RETURNS NUMERIC
And the Java code:
和Java代码:
CallableStatement proc = con.prepareCall("{ ? = call PSSQLPRC(?,?) }");
proc.registerOutParameter(1, Types.NUMERIC);
proc.setString(2,"abc");
proc.setInt(3,10);
proc.execute();