We have an issue with PL/SQL Trigger involving another PL/SQL Procedure & a Java stored procedure.
The trigger will be invoked when ever there is any transaction occurs on a particular table. This calls a PL/SQL Procedure that inturn invokes a Java stored procedure.
The Java stored procedure will reads the data from the table and write it to a text file.
The issue we are facing is that the Java stored procedure is unable to get the latest changes made to the table, which invoked the trigger.
We have 4 records in the table. If we insert another record, then it inturns fires the trigger and that calls the procedure and Java stored procedure.
The Java stored procedure was able to select only the 4 records but not the 5 record which has fired the trigger.
The event of the trigger is mentioned as "after insert/delete/update for each row".
Attached the code for your reference below.
Please let me know if anybody has a solution for this issue.
CREATE OR REPLACE TRIGGER "DEV1"."TR_JOBS" AFTER
OR DELETE OF "COMMENTS", "DAY_OF_MONTH", "DAY_OF_WEEK", "FREQUENCY", "HOUR", "JOB_ID", "MINUTE", "MONTH_OF_YEAR", "SCRIPT_ID", "STATE", "TIME_SETTINGS", "USER_NAME" ON "DEV1"."T_DTJOBS" FOR EACH ROW sp_jobs;
******** PROCEDURE *************
CREATE OR REPLACE PROCEDURE "DEV1"."SP_JOBS" AS LANGUAGE JAVA
* Description : This class is triggered after t_dtjobs table is modified.
* This class gets the active jobs data from DB and writes it into the cronJobs File
* @Class name : BatchCreateCronJobFile
* @Version : 1.0
* @Author : Tata Consultancy Services
* Creation date : 21/02/2004
* Maintenance History
* Change Request Ref Date Modified Modified by Brief Description
public class BatchCreateCronJobFile
* Description : Gets the active jobs data from DB and writes it into the cronJobs File
public static boolean createCronJobsFile()
BufferedWriter l_bufferedWriter = null;
String record = null;
String s_fileNameWithPath = "c:\\test\\abc.txt";
BatchDBConnection batchDBConnection = new BatchDBConnection();
l_bufferedWriter = new BufferedWriter(new FileWriter(new File(s_fileNameWithPath)));
ResultSet rset = batchDBConnection.executeQuery("Select time_settings||' java BatchProcessJob '||job_Id from t_dtJobs");
Statement stmt = rset.getStatement();
System.out.println("Exception is "+e);
* Description : Default Constructor
public static void main (String args)
BatchCreateCronJobFile batchCreateCronJobFile = new BatchCreateCronJobFile();
boolean status = batchCreateCronJobFile.createCronJobsFile();
You don't want to do that! Of course the Java procedure can't see the data, because it runs in a different session (new BatchDBConnection...) and you haven't commited in the first session yet. What's more, you may in fact roll back the triggering statement, in which case you don't want the data written to the file (I presume).
I would suggest that in the trigger you call DBMS_JOB.SUBMIT to schedule a job to run the procedure. The job will only run once the triggering statement is committed, and will not run at all if it rolls back.
Another advantage of this approach is that the session that fired the trigger won't have to wait however long your Java routine takes to write to file before continuing: the write to file will be asynchronous.