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

悠悠隱於市發表於2011-05-02

錯誤如下:

 

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替換成機器名;

 

執行..問題解決..

 

相關文章