Re: Stored procedures

From: Franco Bruno Borghesi <franco(at)akyasociados(dot)com(dot)ar>
To: "Zodiac" <bishop(at)nm(dot)ru>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Stored procedures
Date: 2003-03-29 21:05:21
Message-ID: 200303291805.21844.franco@akyasociados.com.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

As far as I know, you always work with a ResultSet.
If you know your stored procedures will always return an Integer and you don't
wanna deal with the executeQuery and stuff every time, you could create a
class with methods explicitly for accesing your stored procedures, for
example:

assuming you have a pg function returning an INT, called countPeople(), you
could do

public class MyStoredProcs {
private static int executeAnyProc(Connection conn, String procName) throws
SQLException{
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("SELECT * FROM "+procName+"()");
rs.next();
return rs.getInt(1);
}

public static int countPeople() throws SQLException{
return executeAnyProc("countPeople");
}
};

You could add methods to access every stored procedure in your database (even
returning other data types), and you would use it like this in your code:

...
int count=MyStoredProcs.countPeople();
// do something with the value
if (count>100) {
...

hope this is what you were looking for.

On Saturday 29 March 2003 17:35, Zodiac wrote:
> Thank you for help.
> Just one more question. Have i direct access to stored procedure?
> For example, i have procedure which returns Integer and i wanna to have
> ability to write such code " int var = ANY_CALL". Where ANY_CALL is a my
> procedure call.
> I meant must i do "executeQuery" only and after then parse Statement
> variable?
>
> Thank you.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Alain Gougeon 2003-03-29 23:14:38 Re: Off topic : world database
Previous Message Zodiac 2003-03-29 20:35:41 Re: Stored procedures