`

java.sql.SQLException: Io 异常: The Network Adapter could not establish the connec

阅读更多

错误如下:

 

java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
 at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
 at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
 at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
 at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
 at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414)
 at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
 at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
 at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
 at java.sql.DriverManager.getConnection(DriverManager.java:525)
 at java.sql.DriverManager.getConnection(DriverManager.java:171)
 at pack.java.connection.demo.BaseDao.getConnection(BaseDao.java:35)
 at pack.java.connection.demo.BaseDao.<init>(BaseDao.java:23)
 at pack.java.connection.demo.BaseDao.main(BaseDao.java:98)
Oracle 用户名或密码错误!

 

解决方案:

像这种适配器的错误,有很多原因. 比如驱动程序 或者URL写错..

还有,用户名和密码;.

 

如果这些确定没有写错,然后再检查你的oracle安装目录下,比如:F:\oracle\product\10.2.0\db_1\NETWORK\ADMIN

这个目录下的

listener.ora

tnsnames.ora

这两个文件,打开 listener.ora文件.

 

# tnsnames.ora Network Configuration File: F:\oracle\product\10.2.0\db_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =改成你的计算机名称)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

 

 

然后,打开tnsnames.ora文件.把host改成机器名称..因为oracle默认是ip地址..如果你的ip地址变动的话,则自然不匹配原因的ip地址.则会发生错误.

 

# listener.ora Network Configuration File: F:\oracle\product\10.2.0\db_1\network\admin\listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = F:\oracle\product\10.2.0\db_1)
      (PROGRAM = extproc)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 改成你的计算机名称)(PORT = 1521))
    )
  )

 

最后把:

private final String DRIVER   = "oracle.jdbc.driver.OracleDriver";
private final String URL      = "jdbc:oracle:thin:@localhost:1521:ORCL";

 

把localhost替换成机器名;

 

运行..问题解决..

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics