我正在尝试使用jdbc进行oracle os身份验证。
我有solaris sparc 32位机器和oracle 10g。 我在后端有alredy setup os身份验证,用户是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)
请帮我解决这个问题。
答案 0 :(得分: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");