Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating triggers over JDBC (oracle)

Tags:

java

oracle

jdbc

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
like image 472
corydoras Avatar asked Aug 19 '09 04:08

corydoras


People also ask

What is cascading trigger in Oracle?

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.


1 Answers

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;"

like image 119
Gary Myers Avatar answered Oct 06 '22 17:10

Gary Myers