0

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);
3
  • 1
    expdp is 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? Commented Jul 28, 2018 at 15:15
  • yes, expdp is a command line statement. then what should be the SQL statement For this. As I want to control the export and import From Java that's why I am trying to use it from Java Commented Jul 28, 2018 at 15:18
  • There isn't a single SQL statement, but you could work with the API if you really wanted to. Or you can call expdp via getRuntime().exec(). Commented Jul 28, 2018 at 15:22

1 Answer 1

1

You cannot call expdp from SQL. It's a command-line function. There is a PL/SQL API for that called dbms_datapump, which you can call from PL/SQL.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.