我无法使用 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。
任何帮助将非常感激。
--山姆