Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Statement works in database, but fails in Java code -

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
like image 585
sweet dreams Avatar asked Sep 22 '26 11:09

sweet dreams


1 Answers

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.

like image 169
sakthisundar Avatar answered Sep 25 '26 02:09

sakthisundar