Re: Stored procedures - Mailing list pgsql-sql

From Franco Bruno Borghesi
Subject Re: Stored procedures
Date
Msg-id 200303282040.59217.franco@akyasociados.com.ar
Whole thread Raw
In response to Stored procedures  ("Zodiac" <bishop@nm.ru>)
List pgsql-sql
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.

pgsql-sql by date:

Previous
From: Franco Bruno Borghesi
Date:
Subject: returning composite types.
Next
From: "Jordan S. Jones"
Date:
Subject: Re: returning composite types.