Re: CallableStatement and getUpdateCount

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: CallableStatement and getUpdateCount
Дата
Msg-id D960CB61B694CF459DCFB4B0128514C201ED261B@exadv11.host.magwien.gv.at
обсуждение исходный текст
Ответ на CallableStatement and getUpdateCount  (Sam Lawrence <sam@fsbtech.com>)
Ответы Re: CallableStatement and getUpdateCount  (Kris Jurka <books@ejurka.com>)
Список pgsql-jdbc
Sam Lawrence wrote:
> I have a query about using CallableStatement with functions that return
> a SETOF. I know the "Calling Stored Functions" documentation says use a
> Statement or a PreparedStatement - I'm in the process of porting over a
> database and would like to leave my calling code the same - that means
> CallableStatement (more in a moment).
>
> First, an example. A simple function (I know the SETOF is redundant in
> this example, normally it wouldn't be) -
>
>     CREATE OR REPLACE FUNCTION cstest()
>     RETURNS SETOF integer AS
>     $$
>         SELECT 1;
>     $$
>     LANGUAGE 'sql' VOLATILE;
>
> The calling code -
>
>     Class.forName("org.postgresql.Driver");
>     Connection con = DriverManager.getConnection("...");
>
>     CallableStatement cs = con.prepareCall("{call cstest()}");
>     cs.execute();
>
>     System.out.println("update count - should be -1? " + cs.getUpdateCount());
>
>     ResultSet rs = cs.getResultSet();
>     while(rs.next())
>     {
>         System.out.println(rs.getInt(1));
>     }
>     rs.close();
>     cs.close();
>     con.close();
>
> The code works fine and returns the record correctly. My problem is the
> getUpdateCount after the execute - from the java.sql.Statement
> documentation "if the result is a ResultSet object or there are no more
> results, -1 is returned". It actually comes back as 1. Is this a bug or
> have I missed something?
>
> I'm running PostgreSQL 8.3.0 with postgresql-8.3-603.jdbc4.

Hmmm. getUpdateCount() is defined in
org/postgresql/jdbc2/AbstractJdbc2Statement.java as

    public int getUpdateCount() throws SQLException
    {
[...]
        if (isFunction)
            return 1;
[...]
    }

So it will always return 1 for a callable statement.

There is no comment in the source. Does anybody know why that is?

Yours,
Laurenz Albe

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Kris Jurka
Дата:
Сообщение: Re: Deadlock while using getNotifications() and Statement.executeQuery()
Следующее
От: "Shavonne Marietta Wijesinghe"
Дата:
Сообщение: JSP to PostgreSql