Como se conectar ao Oracle como "SYS" do SQL * Plus em Java
Eu quero me conectar ao Oracle comoSYS
do SQL * Plus em Java. Mas não consigo me conectar. Mas eu consigo conectar como usuário nomeadoSCOTT
. Meu snippet de código é o seguinte:
public static void test_script () {
String fileName = "@t.sql";
//t.sql contains "show user" command
String sqlPath = "D:\\";
String sqlCmd = "sqlplus";
// String arg1 = "scott/tiger@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=hostname)(Port=PORT ID))(CONNECT_DATA=(SID=SID)))";
String arg1 = "sys as sysdba/tiger@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=hostname)(Port=PORT ID))(CONNECT_DATA=(SID=SID)))";
//String arg1="/ as sysdba";
String arg2= fileName;
//String arg2="conn /as sysdba";
try {
String line;
ProcessBuilder pb = new ProcessBuilder(sqlCmd, arg1,arg2);
Map<String, String> env = pb.environment();
env.put("VAR1", arg1);
env.put("VAR2", arg2);
//env.put("VAR3", arg3);
pb.directory(new File(sqlPath));
pb.redirectErrorStream(true);
Process p = pb.start();
BufferedReader bri = new BufferedReader
(new InputStreamReader(p.getInputStream()));
BufferedReader bre = new BufferedReader
(new InputStreamReader(p.getErrorStream()));
while ((line = bri.readLine()) != null) {
System.out.println(line);
}
bri.close();
while ((line = bre.readLine()) != null) {
System.out.println(line);
}
bre.close();
System.out.println("\n\n\n");
System.out.println("Done.");
}
catch (Exception err) {
err.printStackTrace();
}
}
}
Quando tento executar esse código, encontro este erro:
SQL*Plus: Release 11.2.0.1.0 Production on Thu Apr 10 11:08:59 2014
Copyright (c) 1982, 2010, Oracle. All rights reserved.
SQL*Plus: Release 11.2.0.1.0 Production
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Use SQL*Plus to execute SQL, PL/SQL and SQL*Plus statements.
Usage 1: sqlplus -H | -V
-H Displays the SQL*Plus version and the
usage help.
-V Displays the SQL*Plus version.
Usage 2: sqlplus [ [<option>] [{logon | /nolog}] [<start>] ]
...
... e o restante das informações de 'uso' do SQL * Plus.
Estou fornecendo erradoarg1
argumento ou existe alguma outra maneira de conectar-se comoSYS
no Oracle através de Java.