无需用户名或密码即可连接到 Oracle
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/211133/
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
Connection to Oracle without a username or password
提问by Jamie Love
Oracle has this concept of allowing database users to be identified by the operating system user who is running the program that is connecting to Oracle. See here.
Oracle 具有允许数据库用户由运行连接到 Oracle 的程序的操作系统用户识别的概念。见这里。
This allows you to do, as that user on a unix machine for example, a command such as:
这允许您以 unix 机器上的用户身份执行以下命令:
sqlplus /
I am attempting to write a Java program for Oracle 10.2 which connects without a username or password. The obvious choice of url:
我正在尝试为 Oracle 10.2 编写一个 Java 程序,该程序无需用户名或密码即可连接。网址的明显选择:
jdbc:oracle:thin:/@localhost:1521:MYDBSID
doesn't work, giving an error (Sorry I don't have the error available right now).
不起作用,出现错误(对不起,我现在没有可用的错误)。
I have attempted many other forms of doing this as well, but with no luck.
我也尝试过许多其他形式的这样做,但没有运气。
Does anyone have any suggestions on how I can connect a Java program to Oracle using the OS identification method?
有没有人对如何使用操作系统识别方法将 Java 程序连接到 Oracle 有任何建议?
采纳答案by Tony BenBrahim
The JDBC Thin driver is a 100% pure Java implementation that cannot collect the needed information from the operating system.
JDBC Thin 驱动程序是 100% 纯 Java 实现,无法从操作系统收集所需信息。
The JDBC OCI driver can do this! Use jdbc:oracle:oci8:/@MYDBSID
, it will require that the Oracle driver be installed on that machine, not a problem if this is a server (and is faster to boot and supports many more features than the thin driver)
JDBC OCI 驱动程序可以做到这一点!使用jdbc:oracle:oci8:/@MYDBSID
,它将要求在该机器上安装 Oracle 驱动程序,如果这是服务器则没有问题(并且启动速度更快,并且比瘦驱动程序支持更多功能)
回答by anjanb
The jdbc driver that oracle ships does NOT have the capability of gathering the OS username and password from the URL that you provide it. Suppose, there are 3rd party JDBC driver providers for ORACLE, one of them might provide the functionality that you're asking for. you should google around.
oracle 提供的 jdbc 驱动程序无法从您提供的 URL 中收集操作系统用户名和密码。假设有用于 ORACLE 的 3rd 方 JDBC 驱动程序提供程序,其中之一可能提供您要求的功能。你应该谷歌一下。
回答by Jamie Love
Thanks to those that answered. We've gone with the OCI driver.
感谢那些回答。我们已经使用了 OCI 驱动程序。
I did find documentation to suggest that Oracle 11g doessupport OS user authentication via the thin driver though:
不过,我确实找到了表明 Oracle 11g确实通过瘦驱动程序支持操作系统用户身份验证的文档:
I don't have an 11g setup to test this on, so I can't be certain this works.
我没有 11g 设置来测试这个,所以我不能确定这是否有效。
回答by Jean de Lavarene
OS authentication support in the JDBC thin driver was added in 11g (you can download the JDBC thin driver from 11.2.0.4 on OTN).
JDBC 瘦驱动程序中的操作系统身份验证支持已在 11g 中添加(您可以在 OTN 上从 11.2.0.4 下载 JDBC 瘦驱动程序)。
Note that you have to allow remote OS authentication on the server (over TCP) otherwise it will only work with sqlplus using IPC or BEQ locally. In your init.ora file, add this:
请注意,您必须允许在服务器上进行远程操作系统身份验证(通过 TCP),否则它只能在本地使用 IPC 或 BEQ 与 sqlplus 一起使用。在您的 init.ora 文件中,添加以下内容:
REMOTE_OS_AUTHENT = TRUE
Then if you user is "osuserdemo" on the client machine, create a database user like this and restart the DB:
然后,如果您的用户是客户端计算机上的“osuserdemo”,请像这样创建一个数据库用户并重新启动数据库:
CREATE USER OSUSERDEMO IDENTIFIED EXTERNALLY;
GRANT CONNECT,CREATE SESSION,RESOURCE TO OSUSERDEMO;
And the JDBC thin driver should be able to connect without any username or password.
并且 JDBC 瘦驱动程序应该能够在没有任何用户名或密码的情况下进行连接。
It's worth noting that this feature - considered as highly unsecured - has been de-supported in 12c.
值得注意的是,此功能 - 被认为是高度不安全的 - 在 12c 中已被取消支持。
回答by RealHowTo
The 11g thin driver can connect using Kerberos authentication.
11g 瘦驱动程序可以使用 Kerberos 身份验证进行连接。
回答by Ricky
try following jdbc:oracle:thin:username/password@localhost:1521:MYDBSID
尝试以下 jdbc:oracle:thin:username/password@localhost:1521:MYDBSID
you need to specify the account information
您需要指定帐户信息
sqlplus / as sysdba on a unix machine which go through the operation system autentication
sqlplus / as sysdba 在经过操作系统认证的 unix 机器上
回答by tunaranch
If you're accessing Oracle from a J2EE appserver, you could achieve a similar end by using JNDI to acquire a datasource.
如果您从 J2EE 应用程序服务器访问 Oracle,您可以通过使用 JNDI 获取数据源来达到类似的目的。
回答by evgeny
jdbc:oracle:oci:@
works with ojdbc6.jar and Oracle 11g2
jdbc:oracle:oci:@
适用于 ojdbc6.jar 和 Oracle 11g2