Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database Updation?

 
Amruta Jegarkal
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48953
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our databases fora.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic