By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,493 Members | 3,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,493 IT Pros & Developers. It's quick & easy.

org.postgresql.util.PSQLException: FATAL: sorry, too many clients already

P: 1
Hi,
Following is my code that does some initial accounts creation in bulk for some purpose.

After creating about 52 accounts it gives the following error:

org.postgresql.util.PSQLException: FATAL: sorry, too many clients already

Unless I am overlooking something , I open only one database connections, making 3 SQL Statatements, 3 ResultSets.

I am running Postgresql Server 9.3
My Postgresql.conf file semms OK with max_connections=100

I would greatly appreciate if somebody can help me resolve my problem

// ****************************************
Expand|Select|Wrap|Line Numbers
  1. public void CreateAccounts()
  2.     {
  3.         PreparedStatement ps1 = null;
  4.         PreparedStatement ps2 = null;
  5.         String sql1 = "SELECT * FROM \"CHART_OF_ACCOUNTS\" "; // WHERE \"ACCOUNT_ACTIVE\" = 'Y' ";
  6.         String sql2 = "SELECT * FROM \"MEMBER_ACCOUNTS\"  ";
  7.         String sql3 = "SELECT * FROM \"ECCS_MEMBERSHIP\" WHERE \"COMPANY_CODE\" = ?  AND \"EMPLOYEE_TYPE\" = ?  AND \"ECCS_MEMBER_NO\" "
  8.                 + " > '5265'  ORDER BY \"ECCS_MEMBER_NO\"  ";
  9.         Statement stmt1 = null;
  10.         Statement stmt2 = null;
  11.         PreparedStatement ps  = null;
  12.         ResultSet rs1 = null;
  13.         ResultSet rs2 = null;
  14.         ResultSet rs3 = null;
  15.         Connection con = null;
  16.         String eccsNo = null;
  17.         String thriftAccountNo = null;
  18.         String sharesAccountNo = null;
  19.         String loanAccountNo = null;
  20.         String dividendAccountNo = null;
  21.         String employeeType = textEmployeeType.getText();
  22.         String companyCode = textCompanyCode.getText();
  23.  
  24.         try {
  25.             con  = postgresoperations.ConnectionPool.getConnection();
  26.             stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
  27.             stmt2 = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
  28.             ps = con.prepareStatement(sql3);
  29.             rs1 = stmt1.executeQuery(sql1);
  30.             rs2 = stmt2.executeQuery(sql2);
  31.             ps.setString(1, companyCode );
  32.             ps.setString(2, employeeType );
  33.             rs3 = ps.executeQuery();
  34.             int  i=0;
  35.             while(rs3.next())
  36.             {
  37.                 try {
  38.               //      con.setAutoCommit(false);
  39.                     System.out.println("in OneTimeMembersAccountsCreation");
  40.              //       String accountNo = rs1.getString("ACCOUNT_NO"); 
  41.  
  42.          //           rs1.moveToCurrentRow(); COMMENTED ON 20-09-2014
  43.          //           rs2.moveToInsertRow();  COMMENTED ON 20-09-2014
  44.  
  45.                     eccsNo = rs3.getString("ECCS_MEMBER_NO");
  46.        //             employeeType = rs3.getString("EMPLOYEE_TYPE"); 
  47.        //             companyCode = rs3.getString("COMPANY_CODE");
  48.                     thriftAccountNo  = MakeupAccountNo(eccsNo, textThriftAccountNo.getText());
  49.                     loanAccountNo  = MakeupAccountNo(eccsNo, textLoanAccountNo.getText());
  50.                     sharesAccountNo  = MakeupAccountNo(eccsNo, textSharesAccountNo.getText());
  51.         //            dividendAccountNo  = MakeupAccountNo(eccsNo, textDividendAccountNo.getText());
  52.  
  53.                     SetChartOfAccounts(rs1,eccsNo, thriftAccountNo, "L", textThriftAccountNo.getText());// , sharesAccountNo, loanAccountNo);
  54.                     SetChartOfAccounts(rs1,eccsNo, loanAccountNo, "A", textLoanAccountNo.getText());
  55.                     SetChartOfAccounts(rs1,eccsNo, sharesAccountNo, "C", textSharesAccountNo.getText());
  56.            //         SetChartOfAccounts(rs1,eccsNo, dividendAccountNo, "L", textDividendAccountNo.getText());
  57.                     SetMemberAccounts(rs2,eccsNo, thriftAccountNo,  sharesAccountNo, loanAccountNo, dividendAccountNo);
  58.                     System.out.println("in CreateAccounts, membeTthriftAcountNo = " + "-" + thriftAccountNo +"-");
  59.            //         rs2.updateInt("FISCAL_YEAR", fiscalYear);
  60.            //         rs2.updateString("ACCOUNT_NO", accountNo);
  61.            //         rs2.updateDouble("BALANCE", 0.00);
  62.            //         rs2.insertRow();
  63.                     i++;
  64.                     if(i==2500)
  65.                         break;
  66.                 } catch(SQLException e) {
  67.                 //    try {
  68.                 //        con.rollback();
  69.                 //    } catch(SQLException ex) {
  70.                 //        System.out.println(ex.getMessage());
  71.                 //    }
  72.                   System.out.println(e.getMessage());
  73.                 }
  74.             }
  75.             con.close(); // close connection
  76.         } catch(SQLException e) {
  77.             System.out.println(e.getMessage());
  78.             e.printStackTrace();
  79.  
  80.         }
  81.  
  82.         System.out.println("DONE======================");
  83.     }
Dec 23 '14 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.