0

I am working with postgresql procedures and trying to call a procedure from my JDBC program. But getting runtime exception saying procedure doesn't exist eventhough I cross-checked and verified that the procedure name is correct. This is what I am doing

 CallableStatement   cs = connection.prepareCall("{call proc1()}");
 cs.executeUpdate();

And here's my proc1 procedure

   create or replace procedure proc1()
as

begin

insert into employee_info values(1,'johnny','1111',43);
-----

end

This is what the output is

   Connection Failed! ERROR: function proc1() does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.

I dont understand why its not working eventhough proc1() exists in database. And what should i Cast?

9
  • there is no create or replace procedure in Postgres Commented Oct 16, 2013 at 10:29
  • oh.Is it? Then how should I create procedure. Actually I am familiar with mysql , oracle and other databases. and i am new to postgres..Can you direct me to a good link which explains postgresql procedures Commented Oct 16, 2013 at 10:32
  • @a_horse_with_no_name No. The procedure is working fine when I execute it manually in database. So nothing wrong with procedure syntax. Commented Oct 16, 2013 at 10:49
  • Then you are not using Postgres. Postgres does not have procedures, only functions, and thus it only has a create or replace function statement. Commented Oct 16, 2013 at 10:59
  • 1
    create procedure is a syntax accepted by PostgresPlus, a postgres fork aimed at oracle compatibility. Commented Oct 16, 2013 at 21:46

3 Answers 3

2

Add correct schema name to callable statement and it shall work. Please refer to below code for example.

CallableStatement   cs = connection.prepareCall("{call yoursSchema.proc1()}");
Sign up to request clarification or add additional context in comments.

Comments

0

Finally, I got the solution. The main problem was with JDBC Driver which I downloaded from the official website. I was using the postgresql driver. I dont know what's wrong with it but It seems like it is not supporting proedures. So I switched to EnterpriseDB(EDB) driver. Now the same program works fine and procedures are getting executed.

I just made these changes 1)Changing Driver 2)Changing Driver Class url from "org.postgresql.Driver" to "com.edb.Driver" 3)Dabase url "jdbc:postgresql://host:port/db to "jdbc:edb://host:port/db"

That's all. Now the procedures works too.

1 Comment

While this may have circumvented your problem, this answer is not really correct. The "standard" JDBC driver for PostgreSQL supports procedures perfectly well. In jOOQ, we've been running integration tests for PostgreSQL for ages now. It's probably due to your "procedure" having been created through PostgresPlus, I believe? It would be great to have an updated answer if you still know what the real problem was.
0

I encounterd the same problems.

I use spring and ibatis to map the sql, when i call procedure in PostgreSQL, it always say that "no function matches the given name and argument types. you might need to add explicit type casts."

I feel so confused, cause I always use {call "schema"."procedure name"(?,?,?)} to interact SQL. Why does output say no "function" brabrara.

finally, I realized the problems occur in JDBC driver , the driver may invoke the old calling mode in bottom level.

So you may try this :

  1. find your applicationContent
  2. find the datasource bean in applicationContent
  3. add ?escapeSyntaxCallMode=call behind datasource's url.

it may solve your problem.

Sorry, English is not my native tongue. so it will be a little messy.

1 Comment

oh, if you worry if it influence your funciton in postgreSQL , you can use "?escapeSyntaxCallMode=callIfNoReturn" also !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.