3
CREATE USER Person identified by 2012;GRANT ALL PRIVILEGES TO Person;

These statements are successfully executed by Oracle 11g (GUI). But, when I copy and paste the above statement exactly and try to execute it by using executeUpdate(String sql), I get the exception below. Why?

java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
3
  • Don't you need to have your queries separated? I mean two separate executeUpdate. Commented Aug 14, 2012 at 7:38
  • You try to execute them as they are, i.e. together ? Commented Aug 14, 2012 at 7:39
  • @MatinKh - I did not know that was necessary. Commented Aug 14, 2012 at 7:44

2 Answers 2

4

You should not give a two different SQL statements as one. There is no way that you can JDBC driver will execute two statements passed as one string.

try to execute them as

Statement stmt = conn.createStatement();
stmt.executeUpdate("CREATE USER Person identified by 2012");
stmt.executeUpdate("GRANT ALL PRIVILEGES TO Person;");

That should do. Cheers.

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

Comments

3

Dependend on your database jdbc driver, the driver will not support executing two statements in one "executeUpdate". You have to do something like:

Statement stmt = conn.createStatement();
for(String statement : statements) {
    stmt.addBatch(statement);
}
stmt.executeBatch();

1 Comment

Thanks ! I wanted to add some extra info about executeUpdate vs executeBatch() here - stackoverflow.com/questions/1143053/…

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.