Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“线程中的异常”;“主要”;java.lang.RuntimeException:org.postgresql.util.psqleException:FATAL:抱歉,已经有太多客户端了_Java_Sql_Sqlexception - Fatal编程技术网

“线程中的异常”;“主要”;java.lang.RuntimeException:org.postgresql.util.psqleException:FATAL:抱歉,已经有太多客户端了

“线程中的异常”;“主要”;java.lang.RuntimeException:org.postgresql.util.psqleException:FATAL:抱歉,已经有太多客户端了,java,sql,sqlexception,Java,Sql,Sqlexception,我的代码中存在此异常,因此: 以下是我有例外的代码: private void assignCoursesToStudents() throws SQLException, ClassNotFoundException, IOException { ConnectionToDatabase connectionToDatabase = new ConnectionToDatabase(); Random random = new Random(); List<Student&

我的代码中存在此异常,因此:

以下是我有例外的代码:

private void assignCoursesToStudents() throws SQLException, ClassNotFoundException, IOException {

    ConnectionToDatabase connectionToDatabase = new ConnectionToDatabase();

Random random = new Random();

List<Student> students = generateStudents();
    for (int i = 0; i < students.size(); i++) {
    int randomNumberOfStudentsToOneCourse = random.nextInt(3) + 1;

    Set<Integer> randomInts = new HashSet();
    while (randomInts.size() < randomNumberOfStudentsToOneCourse) {
        randomInts.add(random.nextInt(10) + 1);
    }
    for (int j = 0; j < randomInts.size(); j++) {
        insertStudentsToCoursesToDatabase(i, j, randomInts,connectionToDatabase);
    }
}
Exception in thread "main" java.lang.RuntimeException: org.postgresql.util.PSQLException: FATAL: sorry, too many clients already
at com.foxminded.sql.util.GeneratedData.insertStudentsToCoursesToDatabase(GeneratedData.java:58)
at com.foxminded.sql.util.GeneratedData.assignCoursesToStudents(GeneratedData.java:41)
at com.foxminded.sql.util.GeneratedData.generateTestData(GeneratedData.java:23)
at com.foxminded.sql.dao.SchoolDaoImplementation.initializeTheDatabase(SchoolDaoImplementation.java:360)
at com.foxminded.sql.Main.main(Main.java:16)
}

我的例外是:

private void assignCoursesToStudents() throws SQLException, ClassNotFoundException, IOException {

    ConnectionToDatabase connectionToDatabase = new ConnectionToDatabase();

Random random = new Random();

List<Student> students = generateStudents();
    for (int i = 0; i < students.size(); i++) {
    int randomNumberOfStudentsToOneCourse = random.nextInt(3) + 1;

    Set<Integer> randomInts = new HashSet();
    while (randomInts.size() < randomNumberOfStudentsToOneCourse) {
        randomInts.add(random.nextInt(10) + 1);
    }
    for (int j = 0; j < randomInts.size(); j++) {
        insertStudentsToCoursesToDatabase(i, j, randomInts,connectionToDatabase);
    }
}
Exception in thread "main" java.lang.RuntimeException: org.postgresql.util.PSQLException: FATAL: sorry, too many clients already
at com.foxminded.sql.util.GeneratedData.insertStudentsToCoursesToDatabase(GeneratedData.java:58)
at com.foxminded.sql.util.GeneratedData.assignCoursesToStudents(GeneratedData.java:41)
at com.foxminded.sql.util.GeneratedData.generateTestData(GeneratedData.java:23)
at com.foxminded.sql.dao.SchoolDaoImplementation.initializeTheDatabase(SchoolDaoImplementation.java:360)
at com.foxminded.sql.Main.main(Main.java:16)

当我尝试在没有类“ConnectionDatabase”的情况下运行代码并直接在我需要的类中建立连接时,我没有出现任何错误。

您是否检查了psotgres并询问了它认为有多少活动连接/客户端?这个数字是否超过当前postgres配置允许的数字?@Gavin我如何增加可能的连接?@Gavin我也不知道如何检查itAh,我也不知道,我在建议调查原因。您需要能够使用pgadmin访问postgres(假设有可用的连接)。我会在谷歌上搜索“Postgres查询可用连接”或“org.postgresql.util.PSQLException:FATAL:对不起,已经有太多客户端了”这是我遇到异常时通常会做的事情,我不知道如何处理solve@Gavin我做到了,但我没有找到任何解决我问题的办法