重复执行多次查询表功能会报错是为什么呢

重复执行多次查询表功能会报错是为什么呢

() {
    Properties properties=Properties()String propertyFile = SelectCommand..getResource().getPath(){
        propertyFile=URLDecoder().(propertyFile)properties.load(FileInputStream(propertyFile))DataSource dataSource= DruidDataSourceFactory.(properties)QueryRunner qr=QueryRunner(dataSource)List<News> list=qr.query(BeanListHandler<>(News.))(list.size()==){
            System..println()}{
            (News emp:list){
                System..println(emp)}
        }
    } (Exception e) {
        System..println()e.printStackTrace()}
}


十一月 18, 2021 10:39:33 下午 com.alibaba.druid.pool.DruidDataSource error

严重: init datasource error, url: jdbc:mysql://localhost:3306/imooc?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true

java.sql.SQLNonTransientConnectionException: Data source rejected establishment of connection,  message from server: "Too many connections"

https://img1.sycdn.imooc.com//climg/61966588095933e817330214.jpg

十一月 18, 2021 10:39:46 下午 com.alibaba.druid.pool.DruidDataSource error

严重: create connection SQLException, url: jdbc:mysql://localhost:3306/imooc?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true, errorCode 1040, state 08004

java.sql.SQLNonTransientConnectionException: Data source rejected establishment of connection,  message from server: "Too many connections"

https://img1.sycdn.imooc.com//climg/619665dc09701fdb17580110.jpg

正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学你好,同学修改下配置文件中的initialSize 和maxActive 试试

initialSize :连接池启动时创建的初始化连接数量

maxActive :连接池中可同时连接的最大的连接数

将初始化数量调小,最大连接数调大试试

祝学习愉快~


  • 小王子WL 提问者 #1

    好的,可能我描述的不是很清楚,我又提了个新问题描述了具体的情况

    2021-11-19 10:34:57
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师