Skip site navigation (1) Skip section navigation (2)

connection problem - why idle

From: dinakar <din_akar(at)yahoo(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: connection problem - why idle
Date: 2004-03-06 05:30:24
Message-ID: 20040306053024.25693.qmail@web10706.mail.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
Hi All, 

 We have hosted an web application and now it is live.


 s/w used : Apache, Tomcat 4.1.x, Postgresql 7.x 

 It seems that there is a major problem with the
database connectivity.  

 What we are seeing is that over a period of time the
database reports more and more connections from the
our web application until the connection limit (100 on
our setup) is reached. 

this is a sample code i am using across application. 

whether we need to release the connection explicitly ?

As of now i have not released the connection only i
have closed it .... ? 

/*****************************************************/

       -------------my db class-----------------
try {
		
	this.setConnection(ConnectionPool.getConnection()); 
	ArrayList arrList = new ArrayList();

	con.setAutoCommit(false);
	preStmt 	= con.prepareStatement("SELECT * from t");
	resultSet 	= preStmt.executeQuery();

	while (resultSet.next()) {
		.....
		.....
	}
	return arrList;	
} 
catch(Exception ex) {
	sberror.append(ex.getMessage());
	return null;
}

finally {
	try {
		con.setAutoCommit(true);
		resultSet.close();
		preStmt.close();
        con.close();
	} 
	catch (SQLException e) {
       	sberror.append(e.getMessage());
		return null;
	}
}


      -----------my Connectionpool class-----------

public static Connection getConnection() {

	Connection con = null;
	javax.sql.DataSource ds;
    try {
    	InitialContext ctx = new InitialContext();
		ds = (DataSource)
ctx.lookup("java:comp/env/jdbc/postgres");
		if (ds != null) {
			con = ds.getConnection();
		}
		else 
			return null;
        }		
	catch (Exception e) {
		return null;
	}
	return con;
}


/*****************************************************/


please help... 

Thanks, 
Dinakar 

__________________________________
Do you Yahoo!?
Yahoo! Search - Find what youre looking for faster
http://search.yahoo.com

In response to

pgsql-jdbc by date

Next:From: dinakarDate: 2004-03-06 05:57:45
Subject: any way in PG to check idle connections and close it automatically
Previous:From: Oliver JowettDate: 2004-03-05 21:29:39
Subject: Re: class not found exception

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group