0

我无法使用 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。

任何帮助将非常感激。

--山姆

4

2 回答 2

0

尝试在连接字符串中替换localhost.localdomainlocalhost,即

jdbc:oracle:thin:@localhost:1521:orcl

如果我用作地址,我也会得到一个The Network Adapter could not establish the connection错误,如果我localhost.localdomain只使用它就会消失localhost

于 2013-12-06T12:37:21.193 回答
0

测试 :

 telnet localhost 1521

如果它不起作用

设置 iptables :

https://exploringspatial.wordpress.com/2013/06/08/installing-oracle-sql-developer/

于 2015-12-04T15:26:45.880 回答