*Hi:*
*How can I abort a delete operation in a Before Delete Trigger? I do it by
throwing an exception if the condition does not allow the delete but
the row is still deleted from my table. Below is my code for the trigger:*
public class AlarmTableTriggers {
public static class AlarmMonitorDelete implements Trigger{
@Override
public void init(Connection conn, String schemaName, String
triggerName, String tableName, boolean before, int type){
}
@Override
public void fire(Connection conn, Object[] oldRow, Object[] newRow)
throws SQLException{
if (oldRow!=null && newRow==null){
Statement stm = conn.createStatement();
ResultSet rs;
rs = stm.executeQuery("SELECT * FROM ALARMMONITOR WHERE
ID=" + oldRow[16].toString());
try{
rs.next();
String MessageText = rs.getString(6);
String AckSource = rs.getString(15);
Timestamp TimeOfAck = rs.getTimestamp(16);
long diffTimeInSeconds = (System.currentTimeMillis() -
TimeOfAck.getTime())/1000;
// The acked record in the AlarmMonitor table should
not be deleted if the current time and acked time is less than 3 secs.
if(MessageText.toUpperCase().contains("T1SVR3") &&
!AckSource.trim().isEmpty() && diffTimeInSeconds <= 20){
throw new SQLException("Delete aborted!"); // throw
an exception to prevent the record being deleted.
}
}
catch(Exception ex){}
}
}
} // end of class AlarmMonitorDelete
}
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.