Jon Doe
Jon Doe

Reputation: 389

JDBC Oracle Alter session missing or invalid option

I am trying to alter the schema for the newly created JDBC connection with the following code:

            Statement stmt = conn.createStatement();
            String sql = "ALTER SESSION SET CURRENT_SCHEMA=abcd;";
            stmt.execute(sql);

This code throws java.sql.SQLSyntaxErrorException: ORA-00922: missing or invalid option

If I try to run the ALTER SESSION SET CURRENT_SCHEMA="abcd"; command through Oracle SQL Developer it successfully alters the schema.

How can I alter the schema through Java?

Upvotes: 1

Views: 2237

Answers (2)

JeroSquartini
JeroSquartini

Reputation: 367

You can't have double quotation marks inside another pair of double quotation marks(" "). In order to do that, you have to diferentiate between the parent quotation marks and the child ones. This can be achieved by using single quotation marks like:

String sql = "yada 'yada' yada"; 

Try this:

String sql = "ALTER SESSION SET CURRENT_SCHEMA='abcd';";

Note: This can be done the other way around, with single quotation marks as parent and double as child.

Upvotes: 0

Bryan
Bryan

Reputation: 169

Try removing the semicolon at the end. "ALTER SESSION SET CURRENT_SCHEMA=abcd"
“ORA-00922: missing or invalid option” when trying to insert into table

Upvotes: 4

Related Questions