日期:2014-05-18  浏览次数:20687 次

eclipse无法连接oracle
代码如下:
import java.sql.*;
public class TestJDBC {

public static void main(String[] args) throws ClassNotFoundExceptionSQLException {

Class.forName("oracle.jdbc.driver.OracleDriver");

Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@127.0.0.1:1521:local", "scott", "tiger");
Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery("select * from dept");

while(rs.next()){
System.out.println(rs.getString("deptno"));
}
}

}

报错:java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
eclipse oracle 连接

------解决方案--------------------
IP的问题吧 试试用户IP地址
------解决方案--------------------
数据库的监听和服务都起了么
------解决方案--------------------
1. 先看"jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger" , SQL plus 是否可以正常连接。也就是说数据库究竟是否启动了orcl这个服务以及监听。

2. 驱动包是否可以找到,版本是否与DBMS匹配。

如果还是连不上,请提供更多的log。
------解决方案--------------------
oracle监听服务没安装成功,卸载重装oracle