Java 如何使用 os 身份验证连接到 oracle 数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19252177/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to connect to oracle database with os authentication?
提问by Mahmoud Saleh
i have oracle 11g databasethat is configured to be connected via os authenticationwith only the alias/tns name of the database and doesn't required username/password.
我有oracle 11g 数据库,该数据库配置为通过os 身份验证连接,仅使用数据库的别名/tns 名称,不需要用户名/密码。
so i was wondering what is the easiest way to make connection to oracle database with os authentication via java, because i tried oci example as in this post java.lang.UnsatisfiedLinkError: no ocijdbc11 in java. library.pathand stuck with it, so please advise if there are other simple ways to make this connection.
所以我想知道通过 java 使用 os 身份验证连接到 oracle 数据库的最简单方法是什么,因为我尝试了 oci 示例,如这篇文章java.lang.UnsatisfiedLinkError: no ocijdbc11 in java。library.path并坚持使用它,所以请告知是否有其他简单的方法来建立这种连接。
采纳答案by Mahmoud Saleh
I was able to accomplish that with JDBC as follows:
我能够使用 JDBC 完成如下操作:
String dbServer="DBSERVER";
String port="1521";
String SID="DBNAME";
String url = "jdbc:oracle:thin:@"+dbServer+":"+port+":"+SID;
Driver driver = new oracle.jdbc.OracleDriver();
DriverManager.registerDriver(driver);
Properties props = new Properties();
//props.setProperty(OracleConnection.CONNECTION_PROPERTY_THIN_VSESSION_OSUSER,osUser);
Connection conn = DriverManager.getConnection(url, props);
you must use the jar ojdbc6.jar
你必须使用 jar ojdbc6.jar
according to this link: http://docs.oracle.com/cd/E18283_01/java.112/e16548/clntsec.htm
根据此链接:http: //docs.oracle.com/cd/E18283_01/java.112/e16548/clntsec.htm
all i needed is to give os access for current machine to this oracle database.
我所需要的只是为当前机器提供对该 oracle 数据库的 os 访问权限。