Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要在 JAVA 中执行一个 sql 文件,并且我知道执行此操作的基本方法:
Process p = Runtime.getRuntime().exec("sqlplus username@orcl/passwd @task.sql")
但是现在在 task.sql 中,我定义了一个变量,其值必须从 java 代码中传递。我怎样才能做到这一点?谢谢!
一种方法是使用原始文件 (task.sql) 作为模板从 java 生成单独的 sql 文件 (task_exec.sql),其中在 task_exec.sql 文件中设置所有变量,因此无需从外部传递参数. 所以你所要做的就是运行生成的sql文件。