英文:
JDBC Oracle Alter session missing or invalid option
问题
我正在尝试使用以下代码更改新创建的JDBC连接的模式:
Statement stmt = conn.createStatement();
String sql = "ALTER SESSION SET CURRENT_SCHEMA=abcd;";
stmt.execute(sql);
这段代码会抛出java.sql.SQLSyntaxErrorException: ORA-00922: missing or invalid option
异常。
如果我尝试通过Oracle SQL Developer运行ALTER SESSION SET CURRENT_SCHEMA="abcd";
命令,它会成功修改模式。
我如何通过Java修改模式?
英文:
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?
答案1
得分: 3
尝试将末尾的分号删除。"ALTER SESSION SET CURRENT_SCHEMA=abcd"
<br>
链接:https://stackoverflow.com/questions/30818416/ora-00922-missing-or-invalid-option-when-trying-to-insert-into-table
英文:
Try removing the semicolon at the end. "ALTER SESSION SET CURRENT_SCHEMA=abcd"
<br>
https://stackoverflow.com/questions/30818416/ora-00922-missing-or-invalid-option-when-trying-to-insert-into-table
答案2
得分: 0
你不能在另一对双引号(" ")之间使用双引号。为了做到这一点,你必须区分父引号和子引号。可以通过使用单引号来实现:
String sql = "yada 'yada' yada";
尝试这样做:
String sql = "ALTER SESSION SET CURRENT_SCHEMA='abcd';";
注意:也可以反过来做,用单引号作为父引号,双引号作为子引号。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论