在tomcat服务器上用数据源获得oracle连接的时候出现了一下异常:
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io 异常: The Network Adapter could not establish the connection)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:855)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at com.thams.util.DBConnection.getConnection(DBConnection.java:16)
at com.thams.struts.action.LoginAction.execute(LoginAction.java:34)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at com.thams.struts.filter.ConvertRequestParameterEncodingFilter.doFilter(ConvertRequestParameterEncodingFilter.java:29)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:404)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:877)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:851)
... 36 more
仔细核对了配置文件,并没有发现什么不妥的地方。
经查,可能是跟环境有关,有可能是防火墙屏蔽了数据库的端口,然后就连到另外的一台电脑的同结构的库果然可以成功获得数据库的连接,怎么样才能消除这个异常呢?
windows自带的防火墙是关闭的
奇虎360的arp防火墙是开着的不过关掉后依然会出现该异常
这次看来不是跟防火墙有关系。
又找到了其他的方法:
手动启动数据库监听
1:开始 → 运行→ 输入CMD→ 进入DOS命令提示界面
d:>lsnrctl
LSNRCTL> start
启动tnslsnr:请稍候...
TNSLSNR for 32-bit Windows: Version 9.2.0.1.0 - Production
系统参数文件为D:/software/oracle92/network/admin/listener.ora
写入D:/software/oracle92/network/log/listener.log的日志信息
监听:(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=//./pipe/EXTPROC0ipc)))
监听该对象时出错: (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=thams-f8b897d5e)(POR
T=1521)))
TNS-12545: 因目标主机或对象不存在,连接失败
TNS-12560: TNS: 协议适配器错误
TNS-00515: 因目标主机或对象不存在,连接失败
32-bit Windows Error: 1001: Unknown error
监听程序未能启动。请参阅上面的错误消息...
或者
LSNRCTL> status
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC0)))
TNS-12541: TNS:无监听器
TNS-12560: TNS: 协议适配器错误
TNS-00511: 无监听器
32-bit Windows Error: 2: No such file or directory
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=thams-f8b897d5e)(PORT=1521)
))
TNS-12545: 因目标主机或对象不存在,连接失败
TNS-12560: TNS: 协议适配器错误
TNS-00515: 因目标主机或对象不存在,连接失败
32-bit Windows Error: 1001: Unknown error
恍然大悟!看来在服务里面启动的listener并没有启动成功
原来是把计算机名改了(公司进行网络改造),原来的计算机名是thams-f8b897d5e现在改为yangsw了,所以oracle监听的目标主机已经不存在了
那怎么样来修复因为修改计算机host带来的异常呢?
在D:/software/oracle92/network/admin下打开listener.ora文件后将HOST后的主机名改为yangsw:
(ADDRESS = (PROTOCOL = TCP)(HOST = yangsw)(PORT = 1521))
或者改成IP也可解决上面遇到问题 (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.191)(PORT = 1521))
修改后再重新运行一下程序,ok!
问题解决了!