3

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

 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: ERROR main() occurred: java.lang.Exception: Error executing query: ALTER TRIGGER XXXX.UPDATE_TEAM_GROUP_TRIGGER DISABLE error=java.sql.SQLException: ORA-01003: no statement parsed

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

4

2 回答 2

3

首先,您正在执行一个executeQuery不是查询的语句。尝试使用execute

无论如何,ALTER 语句是 DDL(数据定义语言)的一部分(SQL 用于查询,DML -Data Manipulation Language- 用于插入/更新/删除)。我不确定 JDBC 对 DDL 的支持程度如何。

于 2013-02-26T16:41:05.917 回答
2

代替

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");
}
于 2013-02-26T16:43:22.323 回答