Consultor Eletrônico



Kbase P27255: How to create JAVA database triggers for SQL-92 clients.
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/27/2009
Status: Verified

GOAL:

How to create JAVA database triggers for SQL-92 clients.

GOAL:

Sample sql-92 Java Triggers

FACT(s) (Environment):

All Supported Operating Systems
Progress 9.x
OpenEdge 10.x

FIX:

Use the CREATE TRIGGER statement. A JAVA trigger is a special type of automatically executed stored procedure.

Example allowing to auto-increase the CustNum field after inserting a new Customer:

CREATE TRIGGER increaseCustNum
AFTER INSERT ON pub.customer
IMPORT
import java.sql.*;
BEGIN

Integer max = new Integer(0);

SQLCursor sqlc = new SQLCursor("SELECT MAX(custNum) FROM pub.customer");

sqlc.open();
sqlc.fetch();

if ( sqlc.found () ) {
max = (Integer) sqlc.getValue(1, INTEGER);
}

sqlc.close();

int maxv = 0;
maxv = max.intValue();
maxv ++;

String stmt = "UPDATE pub.customer SET custNum = " + maxv + " WHERE custNum = 0";
SQLIStatement update_stmt = new SQLIStatement( stmt );
update_stmt.execute();

END;