Newby Question - accessing refcursor.

Поиск
Список
Период
Сортировка
Искать
От
burferd
Тема
Newby Question - accessing refcursor.
Дата
Msg-id
19680083.post@talk.nabble.com
Список
Дерево обсуждения
Newby Question - accessing refcursor. burferd <jarzabek@pobox.com>
Re: Newby Question - accessing refcursor. Kris Jurka <books@ejurka.com>
Re: Newby Question - accessing refcursor. burferd <jarzabek@pobox.com>
Re: Newby Question - accessing refcursor. Kris Jurka <books@ejurka.com>
Re: Newby Question - accessing refcursor. burferd <jarzabek@pobox.com>
Re: Newby Question - accessing refcursor. burferd <jarzabek@pobox.com>
Re: Newby Question - accessing refcursor. Kris Jurka <books@ejurka.com>

I'm just getting started with postgre and jdbc.

I have a stored procedure listed below.

I'm trying to fetch the data returned from the stored procedure with the
method listed below.
When I do, the execute() method throws the following exception:
ERROR: cursor "" does not exist

I'm not sure what is causing this error - 
I suspect it may be because the stored procedure is returning the REFCURSOR
as an OUT parameter rather than as a RETURN parameter.

If this is the case, could someone show me the fix?  
The person writing the stored procedures is having problems returning a
RETURN value 
with OUT parameters.


Thanks.

Java code

    public void fetchUsers()
    {
        String query = "{call get_user_list( ?, ?, ? ) }";
        try
        {
            CallableStatement cs = dbConn.prepareCall( query );
            cs.registerOutParameter(1, java.sql.Types.JAVA_OBJECT);
            cs.registerOutParameter(2, java.sql.Types.INTEGER);
            cs.registerOutParameter(3, java.sql.Types.VARCHAR);
            cs.execute();
            ResultSet results = (ResultSet)cs.getObject(1);
            if( results != null)
            {
                while( results.next() )
                {
                    // Process row
                }                   
                results.close();
                cs.close();
            }
        }
        catch( Exception e)
        {
            System.out.println( "Error: " + e.getMessage()  );
        }
        
    }



Stored procedure

FUNCTION Get_User_List(OUT p_Users REFCURSOR, OUT p_Return_Code INTEGER, OUT
p_Return_Message VARCHAR(100)) RETURNS RECORD AS $$
DECLARE
   l_Rtn_Success              INTEGER := 0;
   l_Rtn_GeneralFailure       INTEGER := 99;

   l_Rtn_Success_Msg          VARCHAR(100) := 'Successful';
   l_Rtn_GeneralFailure_Msg   VARCHAR(100) := 'General Failure';

BEGIN

   p_Return_Code := l_Rtn_GeneralFailure;
   p_Return_Message := l_Rtn_GeneralFailure_Msg;
   
   OPEN p_Users FOR SELECT * FROM Users;

   p_Return_Code := l_Rtn_Success;
   p_Return_Message := l_Rtn_Success_Msg;
   
   RETURN;
   
END;
$$ LANGUAGE plpgsql;

-- 
View this message in context: http://www.nabble.com/Newby-Question---accessing-refcursor.-tp19680083p19680083.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.

В списке pgsql-jdbc по дате отправления
От: Ido M. Tamir
Дата:
От: Kris Jurka
Дата:
FAQ