博客分类:
Tomcat服务器下的应用连接Oracle时报错,出现以下异常:
java.sql.SQLException: Io 异常: Got minus one from a read call
查询数据库连接情况:
Java代码
- SQL> select username,count(username) from v$session where username is not null group by username;
- USERNAME COUNT(USERNAME)
- ------------------------------ ---------------
- SP2 33
- YWTWEBDB 14
- SYS 2
- INFO 1
- MF 658
- UC 183
- 6 rows selected.
Java代码
- SQL> select count(*) from v$session where status=‘ACTIVE‘;
- COUNT(*)
- ----------
- 675
原因不明:表现是数据库的连接数比较大,临时处理是重启数据库,重启后解决,但估计不是最终的解决方法。。重启后的连接情况:
Java代码
- 正常的时候的数据库连接数:
- SQL> select username,count(username) from V$SESSION where username is not null group by username ;
- USERNAME COUNT(USERNAME)
- ------------------------------ ---------------
- SP2 11
- YWTWEBDB 2
- SYS 1
- INFO 1
- MF 79
- MYJIN 1
- UC 19
- 7 rows selected.
以下收集了网上此问题的相关解决方法如下:
http://www.iteye.com/topic/1126453
http://blog.sina.com.cn/s/blog_529aacbd0100t22b.html
http://hi.baidu.com/xjieni/item/1afbff62dab025167cdecc21
摘录如下:
Java代码
- 今日无意中用java连接oracle时,竟出现以下异常,甚是奇怪:
- Caused by: java.sql.SQLException: Io 异常: Got minus one from a read call
- 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) ....
- 问题在重新启动应用后,应用连接oracle时出错,无法启动应用。
- 最后重新启动oracle11g的服务,没有问题了,但是还没有找到具体原因。
- 后来在另外一台应用上也发现同样问题,发现问题的严重性,经过分析可能是驱动问题;在不重新启动oracle11g服务的情况下,替换最新版本的jdbc驱动包,问题解决;
- 出问题的ojdbc14.jar版本:(查看jar包的MANIFEST.MF文件)
- Manifest-Version: 1.0
- Specification-Title: Oracle JDBC driver classes for use with JDK14
- Sealed: true
- Created-By: 1.4.2_08 (Sun Microsystems Inc.)
- Implementation-Title: ojdbc14.jar
- Specification-Vendor: Oracle Corporation
- Specification-Version: Oracle JDBC Driver version - "10.2.0.1.0"
- Implementation-Version: Oracle JDBC Driver version - "10.2.0.1.0"
- Implementation-Vendor: Oracle Corporation
- Implementation-Time: Wed Jun 22 11:19:45 2005
- Name: oracle/sql/converter/
- Sealed: false
- Name: oracle/sql/
- Sealed: false
- Name: oracle/sql/converter_xcharset/
- Sealed: false
- 解决问题的ojdbc14.jar版本:
- Manifest-Version: 1.0
- Specification-Title: Oracle JDBC driver classes for use with JDK14
- Sealed: true
- Created-By: 1.4.2_14 (Sun Microsystems Inc.)
- Implementation-Title: ojdbc14.jar
- Specification-Vendor: Oracle Corporation
- Specification-Version: Oracle JDBC Driver version - "10.2.0.4.0"
- Implementation-Version: Oracle JDBC Driver version - "10.2.0.4.0"
- Implementation-Vendor: Oracle Corporation
- Implementation-Time: Sat Feb 2 11:40:29 2008
- Name: oracle/sql/converter/
- Sealed: false
- Name: oracle/sql/
- Sealed: false
- Name: oracle/sql/converter_xcharset/
- Sealed: false
Java代码
- Caught: java.sql.SQLException: Io 异常: Got minus one from a read call
- 使用JDBC连接Oracle时,多次出现上述错误,后来去网上找了下,基本提供的方法有这么几种:
- 1:数据库连接满了,扩大数据库连接池
- 2:所登录的机子IP不在sqlnet.ora内,加入后重启listerner即可
- 3:数据库负载均衡时,指定了(SERVER=DEDICATED),去除这个即可
- 4:网管在Oracle配置上限制了该台机子访问Oracle的权限,这个问题基本和2类似,也是修改Oracle配置即可;
- 正在寻找解决办法,现在数据库不归我管,不能重启,扩大连接池治标不治本,而且数据库连接池是我自己写的,盲目的扩大会造成其他用户访问的多种问题,最好是能销毁之前创建的那些链接。哎,这就是代码不规范的坏处啊。创建Connection的时候一定不能忘了close,就算连接池也不要忘了returnConnection啊。
Java代码
- 因为,数据库一直都是正常的,所以不可以是那些配置之类的错误。
- 后面DBA查了些东西后,给出结论说是,系统资源不够了。
- --查看系统资源
- SELECT resource_name,
- current_utilization,
- max_utilization,
- LIMIT,
- ROUND (max_utilization / LIMIT * 100) || ‘%‘ rate
- FROM (SELECT resource_name,
- current_utilization,
- max_utilization,
- TO_NUMBER (initial_allocation) LIMIT
- FROM v$resource_limit
- WHERE resource_name IN (‘processes‘, ‘sessions‘)
- AND max_utilization > 0);
- RESOURCE_NAME CURRENT_UTILIZATION MAX_UTILIZATION LIMIT RATE
- ------------------------------ ------------------- --------------- ---------- -----
- processes 312 500 500 100%
- sessions 317 509 555 92%
- 发现是资源不足。
- 处理方法是:
- alter system set processes=1000 scope=spfile;
- alter system set sessions=1110 scope=spfile; 然后重启数据库
- 只是,我重启之后值也都下降了,估计还有其他原因导致资源不足的吧。
原文地址:https://www.cnblogs.com/lcword/p/8228480.html
时间: 2024-10-16 03:12:12