问题
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