通过JBDC连接到Oracle DB时,是否可以添加特定的角色

时间:2018-11-12 18:31:54

标签: oracle

我正在尝试使用Java通过ASM连接到Oracle DB。我想查询ASM特定指标。但是,我只能使用"sysasm"角色来访问它。

以下是我的网址的几个示例:

connectionUrl: "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=*host*)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=+ASM)(INSTANCE_NAME=+ASM1)(UR=A)))"

connectionUrl: "jdbc:oracle:thin:\"sys/*password* as sysasm\"@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=host)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=+ASM)(INSTANCE_NAME=+ASM1)(UR=A)))"

connectionUrl: "jdbc:oracle:thin:@*host*:1521:+ASM1"

我看了看文档,但看不到有关角色和连接字符串的任何信息。

2 个答案:

答案 0 :(得分:0)

“ as sysasm”应应用于用户:

"jdbc:oracle:thin:\"sys as sysasm/*password*\"@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=host)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=+ASM)(INSTANCE_NAME=+ASM1)(UR=A)))"

答案 1 :(得分:0)

    public void connect() throws Exception {
        String connectString;
        Class.forName("oracle.jdbc.driver.OracleDriver");

        connectString = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=*host*)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=+ASM)(INSTANCE_NAME=+ASM1)(UR=A)))"

        System.out.println("Before DriverManager.getConnection");
        try {
            connection = DriverManager.getConnection(connectString, "sys as sysasm", "password_for_sys");
            System.out.println("Connection established");

            connection.setAutoCommit(false);
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("Exception inside connect(): " + e);
            e.printStackTrace();
        }

    }