Io 异常: The Network Adapter could not establish the connection
2014-07-08 19:14
573 查看
今天遇到一个问题,jdbc连接oracle数据库查询数据时报错:
java.sql.SQLException: Io 异常: The Network Adapter could 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(T4CDriverExtension.java:34)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:752)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at net.yhte.db.DBUtil.getConnection(DBUtil.java:20)
at net.yhte.db.DBUtil.main(DBUtil.java:48)
Exception in thread "main" java.sql.SQLException: Io 异常: The Network Adapter could 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(T4CDriverExtension.java:34)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:752)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at net.yhte.db.DBUtil.getConnection(DBUtil.java:20)
at net.yhte.db.DBUtil.main(DBUtil.java:48)
代码如下:
package net.yhte.service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import net.yhte.db.DBUtil;
import net.yhte.db.insert.InsertDB;
public class CommService {
public static void main(String[] args) {
try {
Connection conn = DBUtil.getConnection();
String sql = "select min(id), max(id) from t_sentry_record t";
System.out.println(conn);
PreparedStatement pst = conn.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
while(rs.next()){
System.out.println(rs.getLong(1));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package net.yhte.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* 获得和关闭数据库连接的工具类
* @author tarena
*
*/
public class DBUtil {
public static Connection getConnection() throws Exception{
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@外网:1521:orcl",
"yhte","yhte");
//conn = DriverManager.getConnection(
// "jdbc:oracle:thin:@外网:1521/orcl",
// "yhte","yhte");
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return conn;
}
public static void close(Connection conn){
if(conn !=null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
System.out.println(getConnection());
}
}
从报错的信息中得知是连接数据库时出现问题,所以通过telnet命令查看端口是否开启或被占用,这时又出现了一个问题,oracle数据库装在双网卡的服务器上,telnet外网是可以通的,但是内网却不通,后来查资料说有可能数据库也要在内网的ip中添加监听;最后在jdbc连接Oracle数据库的字符串的IP还是选择了外网的IP。
jdbc:oracle:thin:@外网:1521:orcl
一开始认为是jdbc连接数据的jar包有问题,后来下了几个版本的jar包还是有问题,最后查找jdbc连接数据字符串格式将“jdbc:oracle:thin:@外网:1521:orcl”改成“jdbc:oracle:thin:@外网:1521/orcl”解决问题。
java.sql.SQLException: Io 异常: The Network Adapter could 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(T4CDriverExtension.java:34)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:752)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at net.yhte.db.DBUtil.getConnection(DBUtil.java:20)
at net.yhte.db.DBUtil.main(DBUtil.java:48)
Exception in thread "main" java.sql.SQLException: Io 异常: The Network Adapter could 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(T4CDriverExtension.java:34)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:752)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at net.yhte.db.DBUtil.getConnection(DBUtil.java:20)
at net.yhte.db.DBUtil.main(DBUtil.java:48)
代码如下:
package net.yhte.service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import net.yhte.db.DBUtil;
import net.yhte.db.insert.InsertDB;
public class CommService {
public static void main(String[] args) {
try {
Connection conn = DBUtil.getConnection();
String sql = "select min(id), max(id) from t_sentry_record t";
System.out.println(conn);
PreparedStatement pst = conn.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
while(rs.next()){
System.out.println(rs.getLong(1));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package net.yhte.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* 获得和关闭数据库连接的工具类
* @author tarena
*
*/
public class DBUtil {
public static Connection getConnection() throws Exception{
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@外网:1521:orcl",
"yhte","yhte");
//conn = DriverManager.getConnection(
// "jdbc:oracle:thin:@外网:1521/orcl",
// "yhte","yhte");
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return conn;
}
public static void close(Connection conn){
if(conn !=null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
System.out.println(getConnection());
}
}
从报错的信息中得知是连接数据库时出现问题,所以通过telnet命令查看端口是否开启或被占用,这时又出现了一个问题,oracle数据库装在双网卡的服务器上,telnet外网是可以通的,但是内网却不通,后来查资料说有可能数据库也要在内网的ip中添加监听;最后在jdbc连接Oracle数据库的字符串的IP还是选择了外网的IP。
jdbc:oracle:thin:@外网:1521:orcl
一开始认为是jdbc连接数据的jar包有问题,后来下了几个版本的jar包还是有问题,最后查找jdbc连接数据字符串格式将“jdbc:oracle:thin:@外网:1521:orcl”改成“jdbc:oracle:thin:@外网:1521/orcl”解决问题。
相关文章推荐
- java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection解决方案
- Io 异常: The Network Adapter could not establish the connection 解决方法
- Io 异常: The Network Adapter could not establish the connection
- Io 异常: The Network Adapter could not establish the connection
- Io 异常: The Network Adapter could not establish the connection
- tomcat控制台错误大汇总--1---Io 异常: The Network Adapter could not establish the connection
- Io 异常: The Network Adapter could not establish the connection 解决方法
- 异常java.sql.SQLException: Io exception:The Network Adapter could not establish connection
- 2011/03/23--Io 异常: The Network Adapter could not establish the connection
- Io 异常: The Network Adapter could not establish the connection
- 关于java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
- Io 异常: The Network Adapter could not establish the connection
- Io 异常: The Network Adapter could not establish the connection的三种解决方法
- 关于Io 异常: The Network Adapter could not establish the connection
- Io 异常: The Network Adapter could not establish the connection
- Io 异常: The Network Adapter could not establish the connection解决
- Io 异常: The Network Adapter could not establish the connection
- Io 异常: The Network Adapter could not establish the connection
- java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
- Oracle Io 异常: The Network Adapter could not establish the connection 解决