如何创建 Java 代码以连接到 SQLPlus 并执行一系列命令?我需要执行以下命令来生成 Oracle AWR。
//Connect to DB thru SQLPlus
sqlplus username/password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host_name)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=service_name)))
//After connected
//Execute SQL Query to capture SID1 and SID2 vards
set heading off feedback off lines 800 pages 5000 trimspool on trimout on
set termout off
spool C:\\Temp\\AWR_TEST.html
select output from table(dbms_workload_repository.awr_global_report_html(4194236182,'',SID1,SID2,0))
spool off
set termout on
set heading on feedback 6 lines 100 pages 45
我有以下代码,但我不知道如何在此处调整完整的 SQL 命令。
processBuilder = new ProcessBuilder(
"sqlplus",
"username/password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host_name)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=service_name)))"); //ORACLE
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((currentLine = in.readLine()) != null) {
appendLineToStringBuilder(responseBuilder,String.format("Result Each Line: %s", currentLine));
}