1

As seen here: http://www.postgresql.org/docs/7.4/static/jdbc-callproc.html

// Turn transactions off.
con.setAutoCommit(false);
// Procedure call.
CallableStatement upperProc = con.prepareCall("{ ? = call upper( ? ) }");
upperProc.registerOutParameter(1, Types.VARCHAR);
upperProc.setString(2, "lowercase to uppercase");
upperProc.execute();
String upperCased = upperProc.getString(1);
upperProc.close();

Can I instead do:

// Turn transactions off.
con.setAutoCommit(false);
// Procedure call.
CallableStatement upperProc = con.prepareCall("{call upper( ? ) }");
upperProc.setString(2, "lowercase to uppercase");
upperProc.execute();
upperProc.close();

I just remove the ? before call upper. My query just inserts so I dont need a value. I want to keep it in this forma becuase mysql also uses this format thus I can reuse a lot of code in JAVA.

4
  • 1
    What happens if you try it? Commented Jul 14, 2014 at 16:32
  • 1
    In general, you can call functions with SELECT without the need for CallableStatement (that's how they would be called in psql). Commented Jul 14, 2014 at 16:35
  • 1
    Just use select upper(?). No need for CallableStatement in Postgres Commented Jul 14, 2014 at 16:51
  • 1
    I would like to use call because I also have the sampe procedure name in MySQL. Thus I can reuse code. Postgresql uses the first code snipet as an example. Commented Jul 14, 2014 at 19:05

1 Answer 1

2

The JavaDoc for CallableStatement shows a syntax without a return value:

   {call <procedure-name>[(<arg1>,<arg2>, ...)]}

so if PgJDBC doesn't accept it that's a bug.

You can just leave out the ? =.

Sign up to request clarification or add additional context in comments.

2 Comments

Not necessarily, if there is a return value, than AFAIK it is an error not to declare a parameter to retrieve it.
I would have a r return value but I return null. Basically I just want to do INSERT statements.

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.