agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Franco Bruno Borghesi <franco@akyasociados.com.ar>
To: Zodiac <bishop@nm.ru>
Cc: pgsql-sql@postgresql.org
Subject: Re: Stored procedures
Date: Sat, 29 Mar 2003 18:05:21 -0300
Message-ID: <200303291805.21844.franco@akyasociados.com.ar> (raw)
In-Reply-To: <002a01c2f632$c49f09f0$7d39e2c2@zodiacfhynm2is>
References: <006301c2f579$d21e8a60$7739e2c2@zodiacfhynm2is>
	<200303282040.59217.franco@akyasociados.com.ar>
	<002a01c2f632$c49f09f0$7d39e2c2@zodiacfhynm2is>

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.

view thread (23+ messages)  latest in thread

Message-ID: <200303291805.21844.franco@akyasociados.com.ar>
Permalink:  ../200303291805.21844.franco@akyasociados.com.ar/
Also on:    postgresql.org/message-id/200303291805.21844.franco@akyasociados.com.ar

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: franco@akyasociados.com.ar, bishop@nm.ru
  Subject: Re: Stored procedures
  In-Reply-To: <200303291805.21844.franco@akyasociados.com.ar>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox