Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting trigger information usind JDBC API

 
Mohanraj Naidu
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
How to get trigger information from the database using JDBC API calls. I need to retrieve the entire trigger and its related information from the database for some reason.
Any help will be appreciated
Regards,
<Mohan/>
 
Nagendra Prasad
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any information available via system catalogs can be retrieved as long as the owner (DB User) through which u are obtaining your connection has the rights to do so.
At the end of the day, it is just a database call through a SQL Statement.
I cannot see why you cannot do it.
If you are having specific problems, please post.. and I might be able to tell something more..
best regards,
prasad.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohan,
I may be misinterpreting your question, but, as far as I know, there are no methods in the JDBC API for retrieving information about the database triggers.
Most [O]RDBMS's that support database triggers, store information about the triggers in their data dictionary. Each DBMS has its own proprietary data dictionary, but usually you can access the data dictionary using SQL. So, for example using Oracle, the following query will give you the trigger definition:

So you could "wrap" the above query into an invocation of the "executeQuery()" method in class "java.sql.Statement", for example, and get the informaton that way. However, as I mentioned before, each DBMS data dictionary is different, so the above will only work for Oracle. That's why there is nothing in the JDBC API for returning that information.
Good luck,
Avi.
 
Braj Prasad
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All you need is the select role on catalog objects, to retrive the trigger information.
For eg. in Oracle you would use the following statement:-
select trigger_body from dba_triggers where trigger_name=<your trigger_name>
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic