Does anyone know how to get triggers created over JDBC. It appears that the problem is to do with the semicolon. Any feedback much appreciated.
The following SQL works when run on the database, but not when run using the following Java code:
Connection c=null;
Statement s=null;
try {
c=dataSource.getConnection();
s=c.createStatement();
s.executeUpdate("create or replace trigger startuptrigger after insert on startuptest for each row begin insert into startuptest values(99); end");
s.close();
s=null;
c.close();
c=null;
} catch(SQLException e) {
if(s!=null) { try { s.close(); } catch(Exception f){} }
if(c!=null) { try { c.close(); } catch(Exception f){} }
throw new IOException(e.toString());
}
I have tried s.execute(...) and s.executeUpdate(...) and it makes no difference. I am using the ojdbc5.jar driver. Oracle returns the error:
ORA-04098: trigger 'POLICYUAT.STARTUPTRIGGER' is invalid and failed re-validation
When a statement in a trigger body causes another trigger to be fired, the triggers are said to be cascading. Oracle Database allows up to 32 triggers to cascade at any one time.
The PL/SQL syntax requires a semi-colon at the end of the end at the end. That is the string should be as follows
"create or replace trigger startuptrigger after insert on startuptest for each row begin insert into startuptest values(99); end;"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With