Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

how to automatically detect a row insertion in database

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I want to an application be triggered as soon as a row is inserted in a database. I wwould like to have it happen on an event basis. That is as soon as a row is inserted an oject is created or a function is called. Is there a way to do it?

Thanks
utsav.
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on which database you're using. Many databases have a feature called "trigger", which are stored procedures executed when certain conditions occur (like an insert in a table). Some databases allow stored procedures to be written in Java (Oracle, PostgreSQL with the PL/Java extension, Derby etc.). This wouldn't work if you wanted that object created (or method called) not in the DB but in some external application.
 
utsav gupta
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thanks for your reply.

Is it possible to create an object that can keep a watch on a particular table in java and invoke a method when a row enters. In that way I would be able to generate a code that will common to all types of database.

However my current focus is oracle and db2.
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes - consult the documentation of the DB you're using about "triggers" and "stored procedures written in Java".
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic