Re: Constant "JTable" update

From: Ned Wolpert <ned(dot)wolpert(at)knowledgenet(dot)com>
To: Jean-Christophe ARNU <jc(dot)arnu(at)wanadoo(dot)fr>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Constant "JTable" update
Date: 2001-11-08 17:38:21
Message-ID: XFMail.20011108103821.ned.wolpert@knowledgenet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

So, let me see if I understand correctly... you want your Java application
notifed when the table is updated, right?

You are correct that there isn't a JDBC api call that detects changes in the
database. If I understand the question correctly, then your two main
solutions are :

1) Re-query the table often. (What your doing, and a drag to do. :-)

2) Write a trigger in the database to call an external application which
notifies your Java clients that the table has been update. This isn't a
pure-java solution since the trigger can't be written in Java (yet) but it
should work. If you go this route, see
http://www.postgresql.org/idocs/index.php?programmer-server.html
for how to program triggers, specifically,
http://www.postgresql.org/idocs/index.php?triggers.html will give you
information on triggers and
http://www.postgresql.org/idocs/index.php?programmer-pl.html
will give you information on procedural languages that can be used. (Perl
is a good place to start. See
http://www.postgresql.org/idocs/index.php?plpgsql-trigger.html
for that. You'll still have to build the communications mechanism on how
you want to notify your client (RMI, TCP, other) so the app the trigger
calls can communicated with your Java-clients, but this at least gets you
started.

(Side note for others: Nothing is wrong with having a trigger call a perl
method that does an exec call, right?)

On 08-Nov-2001 Jean-Christophe ARNU wrote:
> Hello to all the pgJDBC communauty!
>
> My problem seems to be quite simple to solve, but I would like to get
> you opinion on the different solutions available for the result to be
> programmed as nicer as it can :
>
> My PostgreSQL database is used as a data storage for measure. On
> process "feeds" the database, inserting measure in a table (measure). On
> the other hand, I have a java program which is used to display such
> results in tables (or charts). Up to there, nothing seems to be easier.
> But I have to display data in "real time". The java program has to be
> notified that a new measure (or data content in the measure table) was
> inserted (repectively has changed).
>
> The straightforward solution seems to have database listeners on the
> table that wakes-up a notifier in the java program. But such kind of
> mechanism seems not to be implemented in the JDBC API (up to my small
> knowledge).
> The second tortuous solutions (the one I use) is to query the database
> relatively often to get the freshest results. This is quite bandwidth
> consumming (assuming that some users should use a quite small bandwidth
> connection). Using this kind of solution makes the Java application
> slow...
>
> My questions are : is there any other solutions (Use of cursor maybe)?
> is the first solution can be implemented while combining JDBC et
> PostgreSQL functionnalities?
>
> Thank you for any remarks/answers/attention paid/flames/rtfm for these
> problems.
>

Virtually,
Ned Wolpert <ned(dot)wolpert(at)knowledgenet(dot)com>

D08C2F45: 28E7 56CB 58AC C622 5A51 3C42 8B2B 2739 D08C 2F45
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE76sMNiysnOdCML0URAumfAJ0QLfz1DpEZcFxK4aNMX3sxTaYckwCfdkmb
1NIgWK4dJTyo2piyzH6Zjhk=
=Yx6P
-----END PGP SIGNATURE-----

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Barry Lind 2001-11-08 17:46:31 Re: Memory exeception
Previous Message Bruce Momjian 2001-11-08 17:37:58 Re: MD5-based passwords