Executing below command from the command line is successful, but executing the same command from a Java class throws an "invalid SQL statement"-error.
EXPDP DCR/DCR2017 DIRECTORY=D33 DUMPFILE=DCR.DMP SCHEMAS=DCR
Java Code:
String sql ="EXPDP DCR/DCR2017 DIRECTORY=D33 DUMPFILE=DCR.DMP SCHEMAS=DCR";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/orcl","DCR","DCR2017");
PreparedStatement prepareStatement = connection.prepareStatement(sql);
boolean execute = prepareStatement.execute();
System.out.println(execute);
expdpis a command-line tool, as you already know as you said that was sucessful. It is not a SQL command. Hence the error you get. You would see the same thing trying to do that from, say, a SQL*Plus prompt. There is PL/SQL package access to data pump, but do you really want to do it that way, or from Java from a system command? Why not just do it from the command line?expdpviagetRuntime().exec().