今天试着用java连接oracle数据库,但是出了异常
所抛异常如下:
Exception in thread "main" java.sql.SQLException: Io 异常: The Network Adapter c
ould not establish the connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:111)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:145)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:254)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:386)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:
413)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:164)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtensio
n.java:34)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:752)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at JDBCOracle.main(JDBCOracle.java:19)
起初上网搜了一下,发现很多人都出现过这个错误,有的说是驱动问题,于是我就把驱动换了一下,结果还是这个错误,我以为是CLASSPATH配置错了,于是又重新配置了CLASSPATH,结果还是这样,然后就试了一下,把jdbc:oracle:thin:@localhost:1521:orcl 中的localhost换成本地IP地址,测试成功,本地IP可以通过cmd-->ipconfig命令获得。