“x is a procedure, use ”call“” when I am already using call

空扰寡人 提交于 2021-02-05 07:09:34

问题


I'm using Postgres 12 and have written this procedure:

CREATE OR REPLACE PROCEDURE reduceStock(id INTEGER, soldQuantity INTEGER)
    LANGUAGE plpgsql AS
    $$
    BEGIN
    UPDATE inventory SET ProductStockAmount = ProductStockAmount - soldQuantity WHERE ProductID = id;     
    END;
    $$;

It works perfectly if I open up psql on the command line and run call reduceStock(1,1);

However, calling it from my Java program as follows:

CallableStatement stmt = conn.prepareCall("{call reduceStock(?, ?)}");
stmt.setInt(1, productID);
stmt.setInt(2, quantity);
stmt.execute();

Gives me the following error:

What I've Tried

  • running call reduceStock(1,1); from the psql client - works perfectly
  • dropping the database and starting over to see if some old definition was cached - didn't work
  • different capitalisations, spacings of call

Any ideas would be appreciated


回答1:


You need to remove the curly braces, which are the JDBC escape for calling a procedure. But because Postgres has it's own call command, they are not needed (and collides with the JDBC escape).

CallableStatement stmt = conn.prepareCall("call reducestock(?, ?)");


来源:https://stackoverflow.com/questions/65116924/x-is-a-procedure-use-call-when-i-am-already-using-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!