0 Replies Latest reply on Dec 13, 2018 12:10 PM by 3490777

    Oracle database type change notifications

    3490777

      I need to get notifications when change the types in oracle database. I found the below code from Database Change Notification. It get the notifications if any change (insert, update, delete) done on the registered table.

       

      public class DBChangeNotification
      {
      static final String USERNAME= "username";
      static final String PASSWORD= "password!";
      static String URL = "jdbc:oracle:thin:@localhost:1521:xe";

      public static void main(String[] argv)
      {
        
      DBChangeNotification demo = new DBChangeNotification();
        
      try
        
      {
        demo
      .run();
        
      }
        
      catch(SQLException mainSQLException )
        
      {
        mainSQLException
      .printStackTrace();
        
      }
      }

      void run() throws SQLException
      {
        
      OracleConnection conn = connect();

        
      Properties prop = new Properties();

        prop
      .setProperty(OracleConnection.DCN_NOTIFY_ROWIDS,"true");

        prop
      .setProperty(OracleConnection.DCN_QUERY_CHANGE_NOTIFICATION,"true");

        
      DatabaseChangeRegistration dcr = conn.registerDatabaseChangeNotification(prop);

        
      try
        
      {
        
      DCNDemoListener list = new DCNDemoListener(this);
        dcr
      .addListener(list);

        
      Statement stmt = conn.createStatement();
        
      ((OracleStatement)stmt).setDatabaseChangeRegistration(dcr);
        
      //ResultSet rs = stmt.executeQuery("select * from type");
        
      ResultSet rs = stmt.executeQuery("select * from table_name");
        
      while (rs.next())
        
      {}
        
      String[] tableNames = dcr.getTables();
        
      for(int i=0;i<tableNames.length;i++)
        
      System.out.println(tableNames[i]+" is part of the registration.");
        rs
      .close();
        stmt
      .close();
        
      }
        
      catch(SQLException ex)
        
      {
        
      if(conn != null)
        conn
      .unregisterDatabaseChangeNotification(dcr);
        
      throw ex;
        
      }
        
      finally
        
      {
        
      try
        
      {
        conn
      .close();
        
      }
        
      catch(Exception innerex){ innerex.printStackTrace(); }
        
      }

        
      synchronized( this )
        
      {
        
      try{ this.wait();} catch( InterruptedException ie ) {}
        
      }
      }
      OracleConnection connect() throws SQLException
      {
        
      OracleDriver dr = new OracleDriver();
        
      Properties prop = new Properties();
        prop
      .setProperty("user",DBChangeNotification.USERNAME);
        prop
      .setProperty("password",DBChangeNotification.PASSWORD);
        
      return (OracleConnection)dr.connect(DBChangeNotification.URL,prop);
      }
      }

      class DCNDemoListener implements DatabaseChangeListener
      {
      DBChangeNotification demo;
      DCNDemoListener(DBChangeNotification dem)
      {
        demo
      = dem;
      }
      public void onDatabaseChangeNotification(DatabaseChangeEvent e)
      {
        
      Thread t = Thread.currentThread();
        
      System.out.println("DCNDemoListener: got an event ("+this+" running on thread "+t+")");
        
      System.out.println(e.toString());
        
      synchronized( demo ){ demo.notify();}
      }
      }

       

      I need to modify this code to get the notifications when user do changes on types. I tried but couldn't found a way to do this. Is there any possibility for that or Please some body can help me to solve this?

      My database version - Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production