0

我正在尝试使用 jdbc 使用 oracle os 身份验证。

我有 solaris sparc 32 位机器和 oracle 10g。我已经在后端设置了操作系统身份验证,用户是 ops$oracle。我正在使用以下代码使用 os 身份验证连接到 db。

String url = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=<host>)"
            + "(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=db1)))";

        //String url = "jdbc:oracle:thin:@<host>:1521:db1";
        Class.forName("oracle.jdbc.OracleDriver");
        Properties props = new Properties();

        props.setProperty(              OracleConnection.CONNECTION_PROPERTY_THIN_VSESSION_OSUSER,              
                "oracle");
        Connection conn = DriverManager.getConnection(url, props);

但是当我运行这段代码时,我得到以下错误::

    java.sql.SQLException: ORA-01017: invalid username/password; logon denied

    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:389)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:382)
    at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:573)
    at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:431)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
    at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:366)
    at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:752)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:366)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at OracleOSAuth.main(OracleOSAuth.java:32)

请帮我解决问题。

4

1 回答 1

0

试试这个代码。

Class.forName("oracle.jdbc.driver.OracleDriver")
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@dbaprod1:1544:SHR1_PRD", username, passwd);
Statement stmt = con.createStatement() ; 
PreparedStatement prepareUpdatePrice = con.prepareStatement( "select * from table");
于 2013-06-12T11:33:18.420 回答