我从DeveloperDaysVM2016 2016-06-02_13下载了http://www.oracle.com/technetwork/database/enterprise-edition/databaseappdev-vm-161299.html,并成功地将其加载到虚拟盒中。
我以“甲骨文”用户的身份登录,我可以看到桌面。
在虚拟机中,我打开了Firefox并导航到:
http://localhost:8080/ords/hrrest/employees/并成功地接收到了一个JSON格式的员工列表。所以我知道数据库已经开始运行了。
现在,我正试图通过Netbeans的"ojdbc6.jar“Java连接器/驱动程序连接到这个数据库(见下图)。然而,
当我进入
用户名:hr密码:oracle SID:orcl12c URL: jdbc:oracle:thin:@localhost:1521:orcl12c
我收到一条错误消息,指示
无法添加连接。无法使用oracle.jdbc.OracleDriver建立到jdbc:oracle:@localhost:1521:orcl12c的连接(ORA-01017:无效用户名/密码;登录拒绝)
但这没有任何意义,因为我能够成功地从终端登录:
sqlplus hr
SQL*Plus: Release 12.1.0.2.0 Production on Thu Jul 7 17:21:07 2016
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Enter password: oracle
Last Successful login time: Thu Jul 07 2016 16:33:31 -04:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> 为什么我不能通过netbeans的java连接器登录呢?
我还检查了
lsnrctl status
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 07-JUL-2016 17:22:12
Copyright (c) 1991, 2014, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 05-JUL-2016 16:48:08
Uptime 2 days 0 hr. 34 min. 4 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Default Service orcl12c
Listener Parameter File /u01/app/oracle/product/12.1.0.2/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/vbgeneric/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=vbgeneric)(PORT=8081))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl12c", status READY, has 1 handler(s) for this service...
Service "orcl12c" has 2 instance(s).
Instance "orcl12c", status UNKNOWN, has 1 handler(s) for this service...
Instance "orcl12c", status READY, has 1 handler(s) for this service...
Service "orcl12cXDB" has 1 instance(s).
Instance "orcl12c", status READY, has 1 handler(s) for this service...
Service "ords" has 1 instance(s).
Instance "orcl12c", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@vbgeneric oracle]$ 那我做错什么了?在这台预先构建好的虚拟机中,一切似乎都在正常运行。

发布于 2018-12-27 21:10:34
这是同一个故事一遍又一遍。Oracle在此VM中使用多租户体系结构,并设置环境变量TWO_TASK。这会引起很多混乱。
当您以sqlplus hr身份连接时,TWO_TASK的值将自动附加到连接字符串,并且您正在连接到SERVICE_NAME=ORCL,而不是SID=ORCL12或SERVICE_NAME=ORCL12。用户hr是在ORCL可插拔数据库中创建的。使用SID=ORCL12或SERVICE_NAME=ORCL12,您可以连接到根容器,在该容器中不存在此用户,因此您将收到ORA-01017错误。

因此,而不是连接字符串:
jdbc:oracle:thin:@localhost:1521:orcl12c
用这个连接:
jdbc:oracle:thin:@localhost:1521/orcl
注意/orcl而不是:orcl12c。
:指定一个实例连接(SID),而/指定一个服务连接(SERVICE_NAME)。在连接到可插拔数据库时,您必须指定服务名称,因为多个可插拔数据库共享同一个实例,而服务的名称正是它们的区别所在。

发布于 2016-07-08 02:45:00
连接字符串还需要包含用户名和密码:
jdbc:oracle:thin:hr/oracle@localhost:1521:orcl12c应该没问题的。
发布于 2017-05-06 17:57:17
使用下拉菜单:驱动程序名称:菜单,并选择/使用Oracle Thin (服务名称)。
(而不是:服务ID (SID))。
https://dba.stackexchange.com/questions/143286
复制相似问题