- Previously, create .jar file. Example:
package procedure;
public class procfortrigger {
public static void aprocfortrigger_afterins(String prm1, String prm2){
String sql="INSERT INTO MYSCHEMA.MYTABLE (MYFIELD1, MYFIELD2) "
+ "VALUES('" + prm1
+ "', '" + prm2
+ "')";
try{
Connection conn = DriverManager.getConnection("jdbc:default:connection");
conn.prepareStatement(sql).execute();
}catch (Exception ex){
System.out.println("err: " + ex);
}
}
}
Compile to .jar file (example: DDA_derby.jar).
- Register that .jar to Derby:
Using Derby GUI, run query:
CALL sqlj.install_jar ('C:/myfolder/DDA_derby.jar', 'APP.DDA_derby', 0);
- Create classpath:
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.classpath', 'APP.DDA_derby');
- Create procedure:
CREATE PROCEDURE APP.APROCFORTRIGGER_AFTERINS(
IN PRM1 VARCHAR(10), IN PRM2 CHAR(10))
PARAMETER STYLE JAVA
MODIFIES SQL DATA
LANGUAGE JAVA
EXTERNAL NAME 'procedure.procfortrigger.aprocfortrigger_afterins';
Deleting .jar:
CALL sqlj.remove_jar ('APP.DDA_derby', 0);
Replacing .jar:
CALL sqlj.replace_jar('C:/myfolder/DDA_derby.jar', 'APP.DDA_derby');
Test:
CALL APP.APROCFORTRIGGER_AFTERINS('123', 'DANIANI');
Do you still want to try?