aspose file tools*
The moose likes JDBC and the fly likes Database Updation? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Database Updation?" Watch "Database Updation?" New topic
Author

Database Updation?

Amruta Jegarkal
Greenhorn

Joined: Nov 29, 2012
Posts: 29
How to know whether a data base is updated with new row?Means my program is hitting DB every 1 minute but how to check whether new row is inserted or not?
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1510
    
    5

Amruta Jegarkal wrote:How to know whether a data base is updated with new row?Means my program is hitting DB every 1 minute but how to check whether new row is inserted or not?

Hi Amruta,

By 'data base is updated with new row' I assume you mean to say 'table is updated with new row'.

In this case, there are several ways (e.g. adding timestamp etc.). I personally would prefer to use a DB sequence in that table.

So, whenever a new row is added, the sequence will be updated (it can be done via query or a trigger on insert), and the program will keep on reading only 'new rows whose sequence id is more than greatest sequence number of last time'.

I hope this helps.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

You could perform a SQL count of rows on the table being updated before and after.

Also, not being rude but updation is not a word, it is simply update.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39879
    
  28
Moving to our databases fora.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

Anayonkar Shivalkar wrote:In this case, there are several ways (e.g. adding timestamp etc.). I personally would prefer to use a DB sequence in that table.

So, whenever a new row is added, the sequence will be updated (it can be done via query or a trigger on insert), and the program will keep on reading only 'new rows whose sequence id is more than greatest sequence number of last time'.

This will probably work in most cases, but not necessarily in all. It is possible to miss added rows in the described setup.

I've already described the problems with finding out recently added rows several times on the Ranch, for example here. (It applies to Oracle. Other databases, which support read uncommitted isolation level, might have no problems finding all added rows, but would have problems weeding out rows that were eventually rolled back.)
 
 
subject: Database Updation?