问题描述
java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection用plsql developer能连接上,但是在程序里面出错了java.sql.SQLException: Io 异常: The Network Adapter could not establish the connectionat 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 com.test.DB.getConn(DB.java:37)at com.test.DB.main(DB.java:60) 问题补充:zengzhangsong 写道
解决方案
引用private final static String DRIVER = "oracle.jdbc.driver.OracleDriver"; private final static String URL = "jdbc:oracle:thin:@l92.168.88.219:1521:gs"; 我去 “l92.168.88.219:1521”, 这个l92 不是数字192 是字母l(大写字母:L) ,不是数字1
解决方案二:
先确认一下,如果是安装Oracle的机器的ip修改了,那Oracle在启动的时候是有问题的,自然你连接的代码中即使ip修改正确了,也是连接不上的,确认一下Oracle的服务启动正常么?如果只是你想连接另外一个Oracle的话就修改jdbc:oracle:thin:@Ip地址:1521:orcl字符串就Ok了,Ip地址修改,端口号修改,实例名(orcl)修改为正确的就OK了
解决方案三:
既然plsql能连接上,那与oracle服务端就没关系。看看驱动包是否正确,防火墙都关了,lz把listener.ora和tnsnames.ora这两个文件弄出来看下?
解决方案四:
检查一下Oracle数据库服务器是否运行正常,oracle的两个必要service是否开启!
解决方案五:
1.确保自己的oracle服务正常运行2.保证class12.jar,oracle的驱动是否正常加载(放在路径下)Class.forName ("oracle.jdbc.driver.OracleDriver");//确保该驱动正确加载Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@ip address:1521:ORA1", "scott", "tiger"); Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery ( "select BANNER from SYS.V_$VERSION" );如果驱动包没有问题,能正常访问。