Re: Errors using JDBC batchUpdate with plpgsql function

From: Hannes Erven <hannes(at)erven(dot)at>
To: pgsql-general(at)postgresql(dot)org
Cc: n(dot)phelge01(at)gmail(dot)com
Subject: Re: Errors using JDBC batchUpdate with plpgsql function
Date: 2015-05-04 10:31:10
Message-ID: 55474A6E.30203@erven.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

> String sql = "select test_user_result_insert_func(?, ?, ?);";

You can't call functions via JDBC like that. You need to use:

CallableStatement cs = connection.prepareCall("{call func(?,?,?)}");

// Loop starts...
cs.clearParameters();
cs.setString(1, "foo");
cs.setString(2, "bar");
cs.setString(3, "baz");
cs.addBatch();
// Loop ends

cs.executeBatch();

See also: https://jdbc.postgresql.org/documentation/94/callproc.html

Best regards,

-hannes

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2015-05-04 11:05:56 Re: Errors using JDBC batchUpdate with plpgsql function
Previous Message Anton 2015-05-04 08:48:02 Re: [HACKERS] optimization join on random value