我刚开始学JDBC 但是怎么却连不上Oracle
抛出Exception in thread "main" java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
不知道为什么 大虾们 帮忙吧
抛出Exception in thread "main" java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
不知道为什么 大虾们 帮忙吧
2.检查端口、防火墙和db监听是否开放
3.检查java代码中jdbc的地址和驱动配置
4.以上都成功,关闭防火墙,重启下db服务试试
import java.sql.*;public class TestJDBC { public static void main(String[] args)throws Exception {
Class.forName("oracle.jdbc.driver.OracleDriver");
//new oracle.jdbc.driver.OracleDriver();
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.16:1521:HeiHei", "HeiHei", "HeiHei"); }}这是我的代码
后来换了别的版本的数据库就没出现这个问题
import java.sql.*; public class TestJDBC { public static void main(String[] args)throws Exception {
try{Class.forName("oracle.jdbc.driver.OracleDriver");
//new oracle.jdbc.driver.OracleDriver();
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.16:1521:HeiHei", "HeiHei", "HeiHei"); }
}catch(Exception e){}
}