mysql中jdbc使用批处理插入数据时,在4000条时抛异常。
com.mysql.jdbc.CommunicationsException: 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.数据源是txt文本,经过java程序读取处理后写入数据库。在4000条左右的public static void addIpInfo(List<IpInfo> ipList){
Connection conn = null;
PreparedStatement ps = null;
String sql = "insert into ip_library (ip1,ip2,startIp,endIp,country,city,areaId) value (?,?,?,?,?,?,?)";
try{
conn = DBHelper.getConnection();
conn.setAutoCommit(false);
ps = conn.prepareStatement(sql);
for(Iterator<IpInfo> iter = ipList.iterator();iter.hasNext();){
IpInfo ipInfo = iter.next();
ps.setDouble(1,ipInfo.getIp1());
ps.setDouble(2, ipInfo.getIp2());
ps.setString(3, ipInfo.getStartIp());
ps.setString(4, ipInfo.getEndIp());
ps.setString(5, ipInfo.getCountry());
ps.setString(6, ipInfo.getCity());
ps.setInt(7, ipInfo.getAreaId());
ps.addBatch();
}
ps.executeBatch();
conn.commit();
}catch(Exception e){
e.printStackTrace();
}finally{
DBHelper.close(ps, conn);
}
}时候报这个异常,执行完sql后都有把connection关闭,但上午曾经插入40多万条没有出错,同样的代码 ,不明白了
com.mysql.jdbc.CommunicationsException: 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.数据源是txt文本,经过java程序读取处理后写入数据库。在4000条左右的public static void addIpInfo(List<IpInfo> ipList){
Connection conn = null;
PreparedStatement ps = null;
String sql = "insert into ip_library (ip1,ip2,startIp,endIp,country,city,areaId) value (?,?,?,?,?,?,?)";
try{
conn = DBHelper.getConnection();
conn.setAutoCommit(false);
ps = conn.prepareStatement(sql);
for(Iterator<IpInfo> iter = ipList.iterator();iter.hasNext();){
IpInfo ipInfo = iter.next();
ps.setDouble(1,ipInfo.getIp1());
ps.setDouble(2, ipInfo.getIp2());
ps.setString(3, ipInfo.getStartIp());
ps.setString(4, ipInfo.getEndIp());
ps.setString(5, ipInfo.getCountry());
ps.setString(6, ipInfo.getCity());
ps.setInt(7, ipInfo.getAreaId());
ps.addBatch();
}
ps.executeBatch();
conn.commit();
}catch(Exception e){
e.printStackTrace();
}finally{
DBHelper.close(ps, conn);
}
}时候报这个异常,执行完sql后都有把connection关闭,但上午曾经插入40多万条没有出错,同样的代码 ,不明白了
解决方案 »
- 往Mysql 插入数据出现Connection.close() has been closed
- 关于日期的问题,急急急
- oracle替换成MySQL,c链接库proc转换的问题
- MySQL相对SQLServer来说,性能差么?
- postgres在vista下不兼容问题,高手求助
- 每个类分别取几条数据
- 权限不够还是有人在操作当前的表?c/mySQL/mysql_real_query()
- 谁告诉我为什么我装好了PGSQL,启动Postmaster时出错啊?
- ERROR 2003: Can't connect to MySQL server on 'localhost' (10061)
- 为什么Mysql会down掉,请各位帮帮忙?
- 请教:针对每组pid,返回时间最早的两个buyTime信息。
- Mysql数据库主键是uuid如何插入数据
可以适当减少其批处理大小。