connection.prepareStatement(“alter session set container = YPDB2”)。executeUpdate()return 0;

问题描述 投票:0回答:1

使用ojbc7连接oracle12c,执行“alter session set container = 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似乎影响零行;

这是否意味着“改变”没有成功?

session jdbc oracle12c alter
1个回答
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时,“容器”确实会改变。

我不知道为什么;

© www.soinside.com 2019 - 2024. All rights reserved.