下面的代码在java中不起作用。
Class.forName('oracle.jdbc.driver.OracleDriver');
Connection connection = DriverManager.getConnection('jdbc:oracle:thin:@localhost:1521:test', 'xyz', 'pass');
PreparedStatement stmt = connection.prepareStatement("set role ? identified by ?");
String role = "TEST_ROLE";
String pswd = "TEST_PASS";
stmt.setString(1, role);
stmt.setString(2, pswd);
stmt.execute();上面的代码抛出了一个异常:
java.sql.SQLSyntaxErrorException: ORA-01937: missing or invalid role name我在成功执行的命令模式下尝试了相同的角色和密码。
发布于 2017-02-26 16:13:04
您只能使用PreparedStatement的绑定变量来绑定值,而不能绑定诸如角色名称或其密码之类的标识符。您必须求助于字符串操作才能获得此效果(假设值不是硬编码的,如上所述,在这种情况下,您只需将它们放入字符串中即可)。例如:
String role = "TEST_ROLE";
String pswd = "TEST_PASS";
String sql = String.format("set role %s identified by %s", role, pswd);https://stackoverflow.com/questions/42466171
复制相似问题