发布日期:2023-03-31来源:武汉北大青鸟武汉校区作者:武汉宏鹏
今天在写一个java类,用jdbc批量更新某表一个字段,该字段需要查询其他多张表进行计算得出,中间用了许多select查询,后拼装成update语句用jdbc操作,当导入到200多条的时候,报错了,提示数据库连接已经用完(我每次调用的时候连接都记得关闭了,程序逻辑没有问题),具体信息如下:
Java代码
15:50:12 [ERROR] com.zyn.hibernate.test.DataSourceHelper.getConnectionByJdbc(76)
使用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.
For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).
-- listing properties --
jdbc.url=jdbc:mysql://192.168.1.211:3306/chart.
jdbc.username=root
jdbc.password=123
15:50:12 [ERROR] com.zyn.hibernate.test.DataSourceHelper.getConnectionByJdbc(76)
使用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.For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).-- listing properties --jdbc.url=jdbc:mysql://192.168.1.211:3306 /chart...jdbc.username=rootjdbc.password=123
Java代码
jdbc.driverClassName=com.mysql.jdbc.Driver
chinahrt.url=jdbc:mysql://192.168.1.211:3306/china...
15:50:12 [ERROR] com.zyn.hibernate.test.JdbcManager.getObjectListBySQL(391)
无法获得数据库连接!
java.lang.RuntimeException: 无法获得数据库连接!
at com.zyn.hibernate.test.DataSourceHelperH
jdbc.driverClassName=com.mysql.jdbc.Driverchinahrt.url=jdbc:mysql://192.168.1.211:3306/china...15:50:12 [ERROR] com.zyn.hibernate.test.JdbcManager.getObjectListBySQL(391) 无法获得数据库连接!java.lang.RuntimeException: 无法获得数据库连接!at com.zyn.hibernate.test.DataSourceHelperH 网上搜索后得知,可以调大数据库的更大连接数来解决该问题,但问题是我没有数据库所在linux服务器的账号和密码,用jdbc操作,也不可能使用hibernate的连接池来解决该问题,自己再写个连接池貌似也划不来,只能采用比较耗时的操作,在进行没次update操作的代码中间加了个 Java代码
try{
Thread.sleep(500);
}catch(Exception e){
e.printStackTrace();
}
try{
Thread.sleep(500);
}catch(Exception e){
e.printStackTrace();
}
以上是学员的java技术学习心得,北大青鸟武汉宏鹏光谷校区会提供更多的学员作品以及教员指导,请继续关注武汉北大青鸟官网。
Copyright (c) 2006-2023 武汉宏鹏教育咨询有限公司 版权所有 All Rights Reserved.