从java禁用触发器

我不完全确定为什么会这样.当我运行命令时:

 ALTER TRIGGER ORIGDV87.UPDATE_TEAM_GROUP_TRIGGER DISABLE/ENABLE

我可以看到它如何改变触发器.我试图从java以编程方式执行此操作:

private void trigger_alter(Connection con, String flag) throws Exception
{
    Query query = new Query(con);
    String selectSql = "select table_owner, trigger_name from user_triggers";
    Query queryTrg = new Query(con);
    query.executeQuery(selectSql);
     while(query.next()) {
        int i = 0;
        String table_owner = query.getColValue("table_owner");
        String trigger_name = query.getColValue("trigger_name");
        String triggerSql = "ALTER TRIGGER " + table_owner + "." + trigger_name + " "+ flag  ;
        System.out.println( triggerSql);
        queryTrg.executeQuery(triggerSql);
    }
    log_obj.FmtAndLogMsg("All triggers have been " + flag+ "D");
}

我得到此异常:2013/02/26 10:38:56.795 TableConverter:发生错误main():java.lang.Exception:执行查询时出错:ALTER TRIGGER XXXX.UPDATE_TEAM_GROUP_TRIGGER DISABLE error = java.sql.SQLException:ORA-01003 :没有语句解析

它是一个oracle数据库,我在Solaris机器上尝试这个.

解决方法:

更换

queryTrg.executeQuery(triggerSql);

con.createStatement().execute(triggerSql);

但是,批量处理ALTER TRIGGER语句会更好:

private void trigger_alter(Connection con, String flag) throws Exception
{
    Query query = new Query(con);
    String selectSql = "select table_owner, trigger_name from user_triggers";

    Statement trgStmt = con.createStatement();

    query.executeQuery(selectSql);
     while(query.next()) {
        int i = 0;
        String table_owner = query.getColValue("table_owner");
        String trigger_name = query.getColValue("trigger_name");
        String triggerSql = "ALTER TRIGGER " + table_owner + "." + trigger_name + " "+ flag  ;
        System.out.println( triggerSql);
        trgStmt.addBatch(triggerSql);
    }

    trgStmt.executeBatch();
    log_obj.FmtAndLogMsg("All triggers have been " + flag+ "D");
}
上一篇:集群中的弹簧集成cron石英?


下一篇:我可以让一个MySQL数据库在插入语句后自动为列赋值吗?