Creating triggers over JDBC (oracle)

Does anyone know how to get triggers created over JDBC. It seems like the problem is with a semicolon. Any feedback is greatly appreciated.

The following SQL works when run in 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 tried s.execute (...) and s.executeUpdate (...), and that doesn't make any difference. I am using the ojdbc5.jar driver. Oracle returns an error:

 ORA-04098: trigger 'POLICYUAT.STARTUPTRIGGER' is invalid and failed re-validation 
+6
java oracle jdbc
source share
2 answers

At the end of the PL / SQL syntax at the end of the end, the end requires a semicolon. This line should be as follows:

"create or replace a startuptrigger after inserting into startuptest for each row; start inserting values ​​into the startuptest (99); end ;"

+4
source share

I tried the above code, and it works great when creating a trigger. Therefore, the reason why this does not work may be:

  • The account you are connecting to does not have permission to create triggers: Try to connect directly and check if you have rights.
  • Manually execute the trigger described above in sqlplus and check if your table exists and you have permission to insert it.
0
source share

All Articles