From: | "Andrew Nelson" <Andrew(dot)Nelson(at)hsc(dot)utah(dot)edu> |
---|---|
To: | <pgsql-jdbc(at)postgresql(dot)org>, <din_akar(at)yahoo(dot)com> |
Subject: | Re: connection problem - why idle |
Date: | 2004-03-06 06:38:17 |
Message-ID: | s0490f7b.035@gwdom2-med.med.utah.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
I don't really know for sure but you should probably be a bit more
carefull when closing your connections.
I personnally am extremly anal and do it as follows.
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
try {
// initialize conn, statements and resultsets here
// then do sql
// ...
rs.close(); rs = null;
stmt.close(); rs = null;
conn.close(); conn = null;
// you may also want to include something like this to see if
connection are ever closed
System.out.println("connection successfully closed in try");
}finally {
if(rs!=null) {
try { rs.close(); } catch(Exception e) {}
}
if(stmt != null) {
try {stmt.close();} catch(Exception e) {}
}
if(conn != null) {
try {conn.close(); System.out.println("connection successfully closed
in finally");} catch(Exception e) {}
}
}
If worst comes to worse you could maybe configure the tomcat connection
pool to start blocking at 99 connections.
>>> dinakar <din_akar(at)yahoo(dot)com> 03/05/04 10:30PM >>>
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 you're looking for faster
http://search.yahoo.com
---------------------------(end of
broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to
majordomo(at)postgresql(dot)org
From | Date | Subject | |
---|---|---|---|
Next Message | Philip A. Chapman | 2004-03-08 04:44:15 | Exception while executing function with CallableStatement |
Previous Message | dinakar | 2004-03-06 05:57:45 | any way in PG to check idle connections and close it automatically |