我不完全确定为什么会这样。当我运行命令时:
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机器上尝试这个。
答案 0 :(得分:3)
首先,您正在使用不是查询的语句执行executeQuery
。请尝试使用execute
。
无论如何,ALTER语句是DDL(数据定义语言)的一部分(SQL用于查询,DML -Data Manipulation Language-用于插入/更新/删除)。我不确定JDBC中支持DDL的程度如何。
答案 1 :(得分: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");
}