您的位置:首页 > 编程语言 > Java开发

求助,关于java链接mysql(数据量较大)

2012-05-05 00:00 260 查看
背景:
把一个很大的xml信息存到数据库里面,xml文件大概有1G,在小数据量下跑过程序,已经没有问题,但是一用大数据量的文件跑就悲剧了,报的是这个错:
-----------------------------------------------------------------------------------------------------------------------------
connect failed!
Exception is: 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.

For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).----------------------------------------------------------------------------------------关于数据库操作部分的代码:
public int selectCount(String dbName , String tableName, String condition) throws InterruptedException
{
String sql = "select count(*) from " +tableName +" where " + condition;
ResultSet dbresult = null;
connectDB(dbName);
int ret = 0;
try{
dbstate = dbconn.createStatement();
dbresult = dbstate.executeQuery(sql);
if(dbresult.next())
ret = dbresult.getInt(1);
}catch(SQLException e) {
printerr("sql is:" + sql);
printerr(e.getMessage());
}
closeDB();
return ret;
}
所有其他操作与之类似,要进行操作前链接,操作完close, 看网上的解答,大部分是说将mysql的最大连接数改大,我将其改大了之后,也只是将处理两千条之后报错改成了处理三千条之后报错而已,目前还没有引进多线程,整个程序是单线程的状态,目前我的mysql最大连接数是1000,感觉已经很大了,可是智能处理到给目标数据库增加4000条左右的数据。感觉单纯通过改大连接数来达到这个效果是个治标不治本的方法。 实在是没辙了,有没有人经历过类似的错误,想问一下有没有其他的解决方案。求各位大神分享方法






内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql java 超过连接数