JDBC连接Oracle时,ALTER SESSION选项丢失或无效。

huangapple go评论80阅读模式
英文:

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. &quot;ALTER SESSION SET CURRENT_SCHEMA=abcd&quot; <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 = &quot;yada &#39;yada&#39; yada&quot;; 

Try this:

String sql = &quot;ALTER SESSION SET CURRENT_SCHEMA=&#39;abcd&#39;;&quot;;

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

huangapple
  • 本文由 发表于 2020年9月17日 01:21:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/63925066.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定