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>
To: pgsql-sql@postgresql.org
Subject: Re: Stored procedures
Date: Fri, 28 Mar 2003 20:40:58 -0300
Message-ID: <200303282040.59217.franco@akyasociados.com.ar> (raw)
In-Reply-To: <006301c2f579$d21e8a60$7739e2c2@zodiacfhynm2is>
References: <006301c2f579$d21e8a60$7739e2c2@zodiacfhynm2is>

Here is a full example of a java program showing the data from a set returning 
function:

-------------------------
--IN YOUR DATABASE
CREATE TABLE people (name TEXT);
INSERT INTO people VALUES ('john');
INSERT INTO people VALUES ('peter');
INSERT INTO people VALUES ('joe');

CREATE FUNCTION getPeople() RETURNS SETOF people AS '
DECLARE
   rec RECORD;
BEGIN
   FOR rec IN
      SELECT name FROM people
   LOOP
      RETURN NEXT rec;
   END LOOP;   
   RETURN;
END;' LANGUAGE 'plpgsql';

-------------------
--ListPeople.java
import java.sql.*;
public class ListPeople {
   public static void main(String[] args) {   
      try {
         Class.forName("org.postgresql.Driver");
         Connection 
con=DriverManager.getConnection("jdbc:postgresql:franco?user=admin");
         Statement stmt=con.createStatement();
         ResultSet rs=stmt.executeQuery("SELECT * FROM getPeople()");
         while (rs.next()) {
            System.out.println(rs.getString("name"));
         }
      }
      catch (Exception e) {
         System.out.println("Exception: "+e.getMessage());
      }
   }
}

On Friday 28 March 2003 19:31, Zodiac wrote:
> Hello!
> Can anybody tell me one thing.
> How can i call stored procedures in my java-programm?
>
> Thanks for any help.

view thread (23+ messages)  latest in thread

Message-ID: <200303282040.59217.franco@akyasociados.com.ar>
Permalink:  ../200303282040.59217.franco@akyasociados.com.ar/
Also on:    postgresql.org/message-id/200303282040.59217.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: <200303282040.59217.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