使用ojbc7连接oracle12c, 执行“更改会话集容器= ypdb2”,似乎不起作用;
但是我使用sqlplus来执行,这是可行的;
这是我的代码;
OracleDataSource oracleDataSource = new OracleDataSource();
oracleDataSource.setURL("jdbc:oracle:thin:@127.0.0.1:1521/orcl");
Connection connection = oracleDataSource.getConnection("sys as sysdba", "123456");
PreparedStatement preparedStatement = connection.prepareStatement("alter session set container=YPDB2");
log.info("{}",preparedStatement.executeUpdate());
控制台打印0 似乎影响零行;
这是否意味着“改变者”没有成功?
答案 0 :(得分:0)
似乎是ojbc的错误;
@Test
public void testAlterSession() throws SQLException {
OracleDataSource oracleDataSource = new OracleDataSource();
oracleDataSource.setURL("jdbc:oracle:thin:@127.0.0.1:1521/ypdb9");
Connection sys_as_sysdba_connection = oracleDataSource.getConnection("sys as sysdba", "123456");
int i = sys_as_sysdba_connection.createStatement().executeUpdate("alter session set container=ypdb9");
log.info("i:{}",i);
List<Map<String, Object>> maps = OdbcUtil.resultSetToList(sys_as_sysdba_connection.createStatement().executeQuery("select * from v$pdbs"));
maps.forEach(map->log.info("{}",map));
sys_as_sysdba_connection.createStatement().executeUpdate("alter session set container=cdb$root");
List<Map<String,Object>> maps2 = OdbcUtil.resultSetToList(sys_as_sysdba_connection.createStatement().executeQuery("select * from v$pdbs"));
maps2.forEach(map->log.info("{}",map));
}
在此测试中,“ excuteUpdate(sql)”返回0,但是当我再次选择pdb时,“容器”确实会更改;
我还不知道为什么;