本文介绍了Arval SQLException:致命:对不起,已经有很多客户已经在postgres的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PostgreSQL 9.1中使用了一个数据库,其中的条目来自另一个程序。我在6秒后从Ajax发送请求以获取最新的entry.tomcat输出窗口显示异常---

I am using a database in PostgreSQL 9.1,in which entry are coming continuously from another program . I am sending request from Ajax after 6 sec to fetch the latest entry.tomcat output window shows exception---

Arval SQLException: FATAL: sorry, too many clients already

并且程序在此之后也正常工作。
当我用查询检查我的postgres时---

and program is working correctly also after this. When i check my postgres with query---

select count(*) from pg_stat_activity;

它显示连接不断增加但我在每次请求后关闭连接。我正在使用netbeans和支柱1.3。

it shows that connection are increasing continuously but I close the connection after each request.I am using netbeans and struts 1.3.

     long previousSNO = Long.parseLong(request.getParameter("previousSNO"));
    if(previousSNO == 0)
    {
        sb.append("SELECT sno,search_type,search_value,search_date FROM log_temp ORDER BY search_date DESC LIMIT 20");
        prest = cb.executeSQLQuery(sb.toString());
        rs = prest.executeQuery();
    }
    else
    {
        sb.append("SELECT sno,search_type,search_value,search_date FROM log_temp WHERE sno > ? ORDER BY search_date DESC");
        prest = cb.executeSQLQuery(sb.toString());    
        prest.setLong(1, previousSNO);
        rs = prest.executeQuery();
    }
    rs.last();
    int c = rs.getRow();
    rs.beforeFirst();

    if(rs!=null && c>0)
    {    
    //code for making json resultsb from resultset here    
    rs.close();
    }
    cb.closeConnection();
    response.setContentType("text/plain");
    response.getWriter().print(resultsb.toString());

//连接bean中的close方法是

//and close method in connection bean is

    public void closeConnection() {
    try {
        // st.close();
        conn.close();
        System.out.println("con is closed");
        conn = null;

    } catch (SQLException e) {
        e.getMessage();
        System.out.println(e.getMessage());
        System.out.println("con is not closed");
    }
}

每次在控制台con关闭时打印;

Every time its print on console " con is closed";

推荐答案

你可以,但这不是解决方案。你有资源泄漏。它可以是任何 - 连接未关闭,结果集未关闭。请返回并查看代码。

You can increase the max_connections in postgres, that is not the solution though. You have resource leaks. It could be any - connection not closed, result set not closed. Please go back and check the code.

考虑使用连接池库,如

Consider using a connection pooling library like c3p0/BoneCp

关于
(感谢@ sinisa229 mihajlovski)

A general discussion on connection pooling is here(Thanks to @sinisa229 mihajlovski)

这篇关于Arval SQLException:致命:对不起,已经有很多客户已经在postgres的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:07