Skip site navigation (1) Skip section navigation (2)

NOTIFY/LISTEN with JDBC

From: "Martin Kresse" <mkresse(at)slyde(dot)in-berlin(dot)de>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: NOTIFY/LISTEN with JDBC
Date: 2000-02-10 08:28:05
Message-ID: 200002100825.JAA05019@mail.vr.IN-Berlin.DE (view raw or flat)
Thread:
Lists: pgsql-interfaces
Hi there,

I'm writing a database application in Java, which needs to get 
notified about changes in the database. Therefore I'd like to use the 
NOTIFY/LISTEN mechanism, but I can't get it working with JDBC. I 
was told, to use connection.getWarnings() method to retrieve 
notifications, which doesn't seem to work. I'm using PostgreSQL 
6.5.1 with the JDBC-Driver 6.5 for jdk1.1, and the following code 
doesn't produce any output, while a parallel running psql-shell 
displays the notifications...

      Connection c = DriverManager.getConnection(...);
      Statement s = c.createStatement();
      s.execute("LISTEN test");

      while(true) {
        s.execute("NOTIFY test");
        SQLWarning w = c.getWarnings();
        if (w != null)
          System.out.println(w.getMessage());
        try {
          Thread.sleep(2000);
        } catch (InterruptedException ex) {}
      }

Am I doing something wrong?
Thanks a lot for your help,

  Martin Kresse

pgsql-interfaces by date

Next:From: Peter MountDate: 2000-02-10 08:42:51
Subject: RE: [INTERFACES] NOTIFY/LISTEN with JDBC
Previous:From: Tomaz BorstnarDate: 2000-02-10 01:55:22
Subject: pgAdmin on NT (NT4SP6)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group