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.PSQLExcept ion: 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
// *************** *************** **********
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.PSQLExcept ion: 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
// *************** *************** **********
Code:
public void CreateAccounts()
{
PreparedStatement ps1 = null;
PreparedStatement ps2 = null;
String sql1 = "SELECT * FROM \"CHART_OF_ACCOUNTS\" "; // WHERE \"ACCOUNT_ACTIVE\" = 'Y' ";
String sql2 = "SELECT * FROM \"MEMBER_ACCOUNTS\" ";
String sql3 = "SELECT * FROM \"ECCS_MEMBERSHIP\" WHERE \"COMPANY_CODE\" = ? AND \"EMPLOYEE_TYPE\" = ? AND \"ECCS_MEMBER_NO\" "
+ " > '5265' ORDER BY \"ECCS_MEMBER_NO\" ";
Statement stmt1 = null;
Statement stmt2 = null;
PreparedStatement ps = null;
ResultSet rs1 = null;
ResultSet rs2 = null;
ResultSet rs3 = null;
Connection con = null;
String eccsNo = null;
String thriftAccountNo = null;
String sharesAccountNo = null;
String loanAccountNo = null;
String dividendAccountNo = null;
String employeeType = textEmployeeType.getText();
String companyCode = textCompanyCode.getText();
try {
con = postgresoperations.ConnectionPool.getConnection();
stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
stmt2 = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
ps = con.prepareStatement(sql3);
rs1 = stmt1.executeQuery(sql1);
rs2 = stmt2.executeQuery(sql2);
ps.setString(1, companyCode );
ps.setString(2, employeeType );
rs3 = ps.executeQuery();
int i=0;
while(rs3.next())
{
try {
// con.setAutoCommit(false);
System.out.println("in OneTimeMembersAccountsCreation");
// String accountNo = rs1.getString("ACCOUNT_NO");
// rs1.moveToCurrentRow(); COMMENTED ON 20-09-2014
// rs2.moveToInsertRow(); COMMENTED ON 20-09-2014
eccsNo = rs3.getString("ECCS_MEMBER_NO");
// employeeType = rs3.getString("EMPLOYEE_TYPE");
// companyCode = rs3.getString("COMPANY_CODE");
thriftAccountNo = MakeupAccountNo(eccsNo, textThriftAccountNo.getText());
loanAccountNo = MakeupAccountNo(eccsNo, textLoanAccountNo.getText());
sharesAccountNo = MakeupAccountNo(eccsNo, textSharesAccountNo.getText());
// dividendAccountNo = MakeupAccountNo(eccsNo, textDividendAccountNo.getText());
SetChartOfAccounts(rs1,eccsNo, thriftAccountNo, "L", textThriftAccountNo.getText());// , sharesAccountNo, loanAccountNo);
SetChartOfAccounts(rs1,eccsNo, loanAccountNo, "A", textLoanAccountNo.getText());
SetChartOfAccounts(rs1,eccsNo, sharesAccountNo, "C", textSharesAccountNo.getText());
// SetChartOfAccounts(rs1,eccsNo, dividendAccountNo, "L", textDividendAccountNo.getText());
SetMemberAccounts(rs2,eccsNo, thriftAccountNo, sharesAccountNo, loanAccountNo, dividendAccountNo);
System.out.println("in CreateAccounts, membeTthriftAcountNo = " + "-" + thriftAccountNo +"-");
// rs2.updateInt("FISCAL_YEAR", fiscalYear);
// rs2.updateString("ACCOUNT_NO", accountNo);
// rs2.updateDouble("BALANCE", 0.00);
// rs2.insertRow();
i++;
if(i==2500)
break;
} catch(SQLException e) {
// try {
// con.rollback();
// } catch(SQLException ex) {
// System.out.println(ex.getMessage());
// }
System.out.println(e.getMessage());
}
}
con.close(); // close connection
} catch(SQLException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
System.out.println("DONE======================");
}