From: | Franco Bruno Borghesi <franco(at)akyasociados(dot)com(dot)ar> |
---|---|
To: | "Zodiac" <bishop(at)nm(dot)ru>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Stored procedures |
Date: | 2003-03-28 23:40:58 |
Message-ID: | 200303282040.59217.franco@akyasociados.com.ar |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Jordan S. Jones | 2003-03-29 00:32:03 | Re: returning composite types. |
Previous Message | Franco Bruno Borghesi | 2003-03-28 23:20:25 | returning composite types. |