JDBC查询大量数据异常问题

当连续对数据库进行查询操作时,出现如下异常:
The driver was unable to create a connection due to an inability to establish the client portion of a socket.

This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable.

For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required.
每次查询完执行:
if(rs!=null){
try {
rs.close();
} catch (Exception e) {
// TODO: handle exception
}
}
//关闭资源[先开后闭];
if(ps!=null){
try {
ps.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ps=null;//使用垃圾回收.
}
if(ct!=null){
try {
ct.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ct=null;
}
我改成每次查询完不关闭connection,但是又报java虚拟机内存不足的异常。
解决办法:
在数据库工具类中设置一个int变量,每次执行数据操作时 ++,当大于1000时执行关闭操作。问题解决。
不知道还有没有更好的方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值