Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 9BECB9FB25B for ; Sat, 28 Jul 2007 04:00:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 57777-07 for ; Sat, 28 Jul 2007 04:00:40 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by postgresql.org (Postfix) with SMTP id D80CC9FB1CD for ; Sat, 28 Jul 2007 04:00:42 -0300 (ADT) Received: (qmail invoked by alias); 28 Jul 2007 07:00:40 -0000 Received: from unknown (EHLO [192.168.1.16]) [85.127.97.149] by mail.gmx.net (mp039) with SMTP; 28 Jul 2007 09:00:40 +0200 X-Authenticated: #1946847 X-Provags-ID: V01U2FsdGVkX1+erBpYV/CeMMJtXq0lwKhpXWlp6F95jf+XzTG4cw Y6qEw+oMOjULz5 Message-ID: <46AAE9CB.7090700@gmx.at> Date: Sat, 28 Jul 2007 09:01:31 +0200 From: Michael Paesold User-Agent: Thunderbird 2.0.0.5 (Windows/20070716) MIME-Version: 1.0 To: vbhatia@ksu.edu CC: pgsql-jdbc@postgresql.org Subject: Re: problem urgent - please help References: <1185588020.46aaa3345f626@webmail.ksu.edu> <46AAC93B.2040305@burntmail.com> In-Reply-To: <46AAC93B.2040305@burntmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/134 X-Sequence-Number: 17308 Guy Rouillier wrote: > vbhatia@ksu.edu wrote: >> I have written a Java application that reads the data from a postgresql >> database and retrieves a particular field, performs some actions on >> that field and finally store the calculated data in some other >> table.The postgresql database, however is changing continuously , since >> new data is being added every minute. My problem is that I want to >> write some trigger in my java application that would be invoked as soon >> as there is a change in the database and perform the above actions for >> that newly added row. > > You can write a trigger in Java. If you're asking if a trigger in > PostgreSQL can invoke your standalone Java program, the short answer is > no. You can probably rig something up using an untrusted PL language, > though. There is no untrusted Java implementation, though, so you'd > have to use another one to implement the glue code. Sounds like your > best bet would be to write a trigger in Java, and just run the whole > thing in the DB. Another option would be to use LISTEN/NOTIFY. You would have a Java thread LISTENING on events, and use triggers on tables (e.g. using PL/pgSQL) to NOTIFY the thread on updates. Than the Java code can do what ever is needed. See the documentation (Server): http://www.postgresql.org/docs/8.2/static/sql-listen.html http://www.postgresql.org/docs/8.2/static/libpq-notify.html And for the JDBC interface: http://jdbc.postgresql.org/documentation/82/listennotify.html Perhaps that helps. Best Regards Michael Paesold