Results 1 to 9 of 9
  1. #1
    nenadm is offline Member
    Join Date
    Nov 2008
    Posts
    19
    Rep Power
    0

    Default Gui-Database_automaticRefresh

    Hello,

    In my Swing application i need ability to automatically refresh GUI according to changes in database (without user request). Persistence is done through JavaBeans objects.
    Any idea how to accomplish this?

    Thanks.

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    765
    Rep Power
    6

    Default

    Hi,
    Based on the component type you need to call repaint() or validate() or update() method immediatley after the database changes.

    Which component u are using in Swings?

    -Regards
    Ramya
    Ramya:cool:

  3. #3
    nenadm is offline Member
    Join Date
    Nov 2008
    Posts
    19
    Rep Power
    0

    Default Gui-Database_automaticRefresh

    Thanks Ramya,

    I know that i need to call repaint() or validate() methods, but i need somehow
    to get event automatically from database that table is changed, so that i can call repaint() method. Is there some way in Java to be notified when database table
    is changed. Other approaches will be to refresh GUI view on user action, or to
    set some timer and do refreshing from application, but both solutions are irrelevant
    with changes in database. E.g. it is likely that refreshing will be done when there
    is no change in database at all.

    Best regards.

  4. #4
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    The following might help you


    ResultSet (Java 2 Platform SE v1.4.2))

    Look on rowInserted(),rowUpdated() and rowDeleted() methods.
    Last edited by dswastik; 07-06-2009 at 02:25 PM.

  5. #5
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    765
    Rep Power
    6

    Default

    Hi,
    U have to explicitly write a code to check the database changes.

    1.Create a separate table

    2.Fire a trigger in a changing table that whenever changes occur,put an entry into the table created in step 1
    along with the flag "yes"

    3.U put a scheduler in the code.It checks the table created in step 1.(But,raises perfomance overhead)

    If it finds "yes" then it refreshes the gui and updates the flag as "No" in the table created in step 1.

    4.Again,if changes occur next time in database then step 2 and 3 will be repeated.



    -Regards
    Ramya
    Last edited by RamyaSivakanth; 07-06-2009 at 02:53 PM.
    Ramya:cool:

  6. #6
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Java Code:
    public interface DBChangeListener{
    	public void dbValueUpdated();
    }
    
    
    public class GUIForm extends JFrame implements DBChangeListener{
    	//other codes
    	BeanClass _bClass;
    	public GUIForm(){
    		_bClass=new BeanClass(this);
    	}
    	
    	public void dbValueUpdated(){
    		//repaint update the form
    	}
    }
    
    
    
    
    public class BeanClass{
    	DBChangeListener _listener;
    	public BeanClass(DBChangeListener listener){
    		this._listener=listener;
    	}
    	
    	public void insertRow(){
    		_listener.dbValueUpdated();
    	}
    }

  7. #7
    nenadm is offline Member
    Join Date
    Nov 2008
    Posts
    19
    Rep Power
    0

    Default Gui-Database_automaticRefresh

    Thank you all,

    @dswastik
    If i am right, you suggests to get data from database in ResultSet and
    then to monitor rowInserted, rowUpdated and rowDeleted methods on
    that ResultSet? I read somewhere that is only possible to get UPDATE
    changes when someone externally change data contained in ResultSet.

  8. #8
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Sorry about that, kindly look at my last post.

  9. #9
    nenadm is offline Member
    Join Date
    Nov 2008
    Posts
    19
    Rep Power
    0

    Default Gui-Database_automaticRefresh

    Thanks dswastik,

    However i don't see in your code any mechanism how database
    notifies client application about change in database.

    @Ramya
    I will try your idea, however i will still need to query the database every few seconds on one table to see is there any new triggered event.

    Meanwhile i find out that some databases have Database Change
    Notification mechanism (Oracle, PostgreSQL) to directly notify client application, but i don't know is it good idea to use that.
    Does someone have experience in using Database Change
    Notification?

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •