我想创建一个Java应用程序,该应用程序能够将DB对象编译为DB模式,例如编译过程,包,函数,触发器,表创建/更改,我可以通过callablestatement运行该应用程序吗?有什么建议吗?
答案 0 :(得分:0)
您必须打开一个SQL连接并运行compile-commands
ALTER PACKAGE mySchema.MyPackage COMPILE;
ALTER VIEW myScham.MyView COMPILE;
等等。
有多种打开连接和运行命令的方法。但这是我想的另一个问题。
答案 1 :(得分:0)
您可以通过JDBC API直接完成此操作:
Connection connection = getConnection(); // implement this anyhow
// way 1
String createProc = "CREATE OR REPLACE PROCEDURE my_proc IS BEGIN NULL; END";
Statement stmt1 = connection.prepareStatement(createProc);
stmt1.execute();
// way 2
String alterCompilePkg = "ALTER PACKAGE my_package COMPILE";
Statement stmt2 = connection.createStatement();
stmt2.executeUpdate(alterCompilePkg);
第一种和第二种方式都对执行DDL有效。 因此,您可以执行任何DDL语句。寻找more examples。 使用后请不要忘记关闭语句。