我无法使用jdbc连接到oracle数据库。
错误: 无法连接到jdbc上的数据库:oracle:thin:@ localhost.localdomain:1521:orcl(用户名:system,密码:tiger)
但是,我可以使用sqlplus命令连接它。
这是日志:
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
Version = Sun GlassFish Enterprise Server v2.1
Testing Database Connection ...
-- Failure! java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
这是listener.ora:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /home/oracle/app/oracle
输出lsnrctl:
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=::1)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
tnsnames.ora的内容:
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
我正在使用Oracle 11g,glassfish服务器2.1,Redhat linux企业版6。
任何帮助都会非常感激。
- 萨姆
答案 0 :(得分:0)
尝试在连接字符串中用localhost.localdomain
替换localhost
,即
jdbc:oracle:thin:@localhost:1521:orcl
如果我使用The Network Adapter could not establish the connection
作为地址,我也会收到localhost.localdomain
错误,如果我只使用localhost
,它就会消失。
答案 1 :(得分:0)
测试:
telnet localhost 1521
如果它不起作用
设置iptables:
https://exploringspatial.wordpress.com/2013/06/08/installing-oracle-sql-developer/