tags:

views:

131

answers:

7

I have a scenario where my Java program has to continuously communicate with the database table, for example my Java program has to get the data of my table when new rows are added to it at runtime. There should be continuous communication between my program and database.

If the table has 10 rows initially and 2 rows are added by the user, it must detect this and return the rows.

My program shouldn't use AJAX and timers.

A: 

Not the simplest problem, really.

Let's divide it into 2 smaller problems:

1) how to enable reloading without timers and ajax

2) how to implement server side

  1. There is no way to notify clients from the server. So, you need to use flash or silverlight or JavaFX or Applets to create a thick client. If the problem with Ajax is that you don't know how to use it for this problem then you can investigate some ready-to-use libraries of jsp tags or jsf components with ajax support.

  2. If you have only 1 server then just add a cache. If there are several servers then consider using distributed caches.

Roman
+3  A: 

If the database you are using is Oracle, consider using triggers, that call java stored procedure, that notifies your client of changes in the db (using JMS, RMI or whatever you want).

folone
A: 

If you have a low-traffic database you could implement a thread that rapidly checks for updates to the DB (polling).

If you have a high-traffic DB i wouldn't recommend that, 'cause polling creates much additional traffic.

cyphorious
+2  A: 

Hey,

without Ajax and timers, it not seems to do this task.

I have also faced the same issue, where i need to push some data from server to client when it changes.

For this, you can user Server push AKA "Comet" programming.

In coment

  • we make a channel between client and server, where client subscribes for particular channel.
  • Server puts its data in the channel when it has it.
  • when client reads the channel, it gets all the data in the channel and channel is emptied.
  • so every time client reads from channel, it will get new data only.

Also to monitor DB changes, you can have two things,

  1. Some trigger/timer (Check out Quartz Scheduler)
  2. Event base mechanism, which pushes data in the channel on particular events.

basically, client can't know anything happening on server side, so you must push some data or event to tell client that, i have some new data, please call some method. Its kind of notification. So please check in comet/server push with event notification.

hope this helps.

thanks.

Paarth
A: 

server notifying client is not a good idea (consider a scenario with a 1000 clients). Do u use some persistence layer or u have to stick to pure JDBC?

Elijah
yea i have a persistence layer and my database is DB2. kindly advise.
deathcaller
A: 

thanks all,

All i need to do is to write a method in java which keeps on monitoring my table and refresh my dataset in the UI when the underlying table is changed(some rows added or removed). My database is realtime one, where users are added continuously at regular intervals hence it should not use polling since it causes performance issues Do to other reasons i must avoid using AJAX.

Some one mentioned the use of Java RMI can you please suggest me how to do it using RMI, will i able to acheive this task using RMI ?

deathcaller
A: 

If you have binary logs turned on in MYSQL , you can see all of the transactions that occur in the database.

Milhous