在myeclipse6.0中写了个连接oracle9i的程序,代码如下:
public static void main(String[] args) {String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@192.168.1.8:1512:ora92";
String username="scott";
String password="tiger";
String sql = "select * from student";
try {
Class.forName(driver);
Connection conn = DriverManager.getConnection(url,username,password);
//Statement stat=conn.createStatement();
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
System.out.println(rs.getString("name")+rs.getString("age"));
}
rs.close();
pstmt.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
运行是总是报错:Io 异常: The Network Adapter could not establish the connection我上网查了下说的试了下还是没解决!!!我的jdk是1.5的,myeclipse是6.0的,用的oracle的驱动是ojdbc5!!!郁闷几天了,求高手解救!!!
public static void main(String[] args) {String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@192.168.1.8:1512:ora92";
String username="scott";
String password="tiger";
String sql = "select * from student";
try {
Class.forName(driver);
Connection conn = DriverManager.getConnection(url,username,password);
//Statement stat=conn.createStatement();
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
System.out.println(rs.getString("name")+rs.getString("age"));
}
rs.close();
pstmt.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
运行是总是报错:Io 异常: The Network Adapter could not establish the connection我上网查了下说的试了下还是没解决!!!我的jdk是1.5的,myeclipse是6.0的,用的oracle的驱动是ojdbc5!!!郁闷几天了,求高手解救!!!
不是1521么?端口号,一般。
192.168.1.8服务器防火墙关了么?看是否拒绝了。
1、telent 192.168.1.8 1521 看看是否服务器是否通
2、使用PL/SQL在客户端连接下数据库看是否可以
你的代码我觉得无什么问题
Oracle Net Configuration Assisant