commons-user mailing list archives

How did this occur?
I am using Oracle8i JDBC type 4 driver version 12
The following code can run 10,000 iterations no problems.
public void runTest(int loops)
throws SQLException
{
Connection conn = getConnection("DXSELL");
ResultSet[] store = new ResultSet[loops];
for (int i = 1; i <= loops; i++) {
Statement s = null;
try {
s = conn.createStatement();
ResultSet r = s.executeQuery("select "+ i +"
from dual");
r.next();
r.getInt(1);
store[i-1] = r; --prevent any gc side
effects
} catch (Exception ex) {
System.err.println("failure on loop " + i);
ex.printStackTrace();
} finally {
quickClose(s);
}
}
quickClose(conn);
System.out.println("finished " + loops + " loops");
}
public static boolean quickClose(Statement databaseObject)
{
boolean correctCompletion = true;
try {
databaseObject.close();
} catch (SQLException eSQL) {
correctCompletion = false;
} catch (NullPointerException eNull) {
correctCompletion = false;
}
return correctCompletion;
}
Rem out the close of Statement and it bails on the 199th attempt with too
many open cursors...
Matt Hope
-----Original Message-----
From: Chris Forbis [mailto:chris.forbis@veritas.com]
Sent: 25 April 2003 16:39
To: 'Jakarta Commons Users List'
Subject: RE: DBCP: Closed connections
I would agree it should be a waste, but after much testing with at least the
Oracle 8i JDBC driver it does not. The resultSet is left open causing a
cursor issue on the database. So for safety I got in the habit of always
doing it.
-----Original Message-----
From: Hope, Matthew [mailto:Matthew.Hope@capitalone.com]
Sent: Friday, April 25, 2003 3:43 AM
To: 'Jakarta Commons Users List'
Subject: RE: DBCP: Closed connections
Statement.close() javadoc contract guarantees that it will cascade close()
to the ResultSet...
Closing them both seems a waste. Though it would protect you from a crappy
implementation not obeying the contract...
It is somewhat annoying that code of the form
Statement s = conn.getConnection();
try {
...
} catch (SQLException e) {
...
}
Finally
{
if (s != null) {
try {
s.close();
} catch (SQLException e) {
// do nothing since we aren't interested
}
}
}
Exists everywhere.
I tend to add 3 overloaded methods to some Database utility class
Already in use in the application. Would be good to have these in some class
so we wouldn't have to keep using them. (the boolean is just in case you
really want to know if close() got called succesfully)
public static boolean quickClose(Statement s)
{
if (s != null) {
try {
s.close();
return true;
} catch (SQLException e) {
// do nothing since we aren't interested
}
}
return false;
}
Matt
-----Original Message-----
From: Chris Forbis [mailto:chris.forbis@veritas.com]
Sent: 24 April 2003 16:49
To: 'Jakarta Commons Users List'
Subject: RE: DBCP: Closed connections
Yea that would be a major issue :)
A procedure that is good to have around :)
//Feel free to pass null in when they are not needed...
public static void closeDatabaseObjects( Connection conn, Statement stm,
ResultSet rs) {
if (rs!=null) {
try {
rs.close();
} catch (SQLException e) {
System.err.println("Error on ResultSet close ("+e.toString()+")");
}
}
if (stm!=null) {
try {
stm.close();
} catch (SQLException e) {
System.err.println("Error on Statement close ("+e.toString()+")");
}
}
if (conn!=null) {
try {
conn.close();
} catch (SQLException e) {
System.err.println("Error on Connection close ("+e.toString()+")");
}
}
}
-- a use of this --
Conenction conn = null;
Statement stm = null;
ResultSet rs = null;
try{
conn = myGetNewConnectionFromPoolCode();
stm = conn.createStatement();
rs = stm.executeQuery("some select query");
while (rs.next()){
//do stuff with the result
}
} catch (SQLException e) {
//Some error code
} finally {
closeDatabaseObjects( conn, stm, rs );
//or just closeDatabaseObjects( null, stm, rs); if you don't want to close
the database Connection
}
-----Original Message-----
From: Behrens Matt - Grand Rapids [mailto:Matt.Behrens@Kohler.Com]
Sent: Thursday, April 24, 2003 7:25 AM
To: Jakarta Commons Users List
Subject: Re: DBCP: Closed connections
Chris Forbis wrote:
> Don't know if this is your issue but I had the same issue and it took me
> forever to track down... It all came back to the following code...
>
> //Stm = Statement
> //Rs = ResultSet
>
> stm.close();
> rs.close();
>
> The problem was simple, because of the order of these is wrong the
> connection pool got messed up bad.
>
> Had to change to
> rs.close();
> stm.close();
>
> and all started working fine...
I don't close my ResultSets or Statements -- just the connections. I
suppose this could be a problem, actually. I don't know.
I've had a few little issues like that. Most memorable was when I had
inexplicable hangs (this is an interactive server app where the users
come in via telnet), and I beat my head against the wall for a little
bit before I realized I was just running out of connections because I
never explicitly returned a few to the pool...
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
**************************************************************************
The information transmitted herewith is sensitive information intended only
for use by the individual or entity to which it is addressed. If the reader
of this message is not the intended recipient, you are hereby notified that
any review, retransmission, dissemination, distribution, copying or other
use of, or taking of any action in reliance upon this information is
strictly prohibited. If you have received this communication in error,
please contact the sender and delete the material from your computer.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
**************************************************************************
The information transmitted herewith is sensitive information intended only
for use by the individual or entity to which it is addressed. If the reader
of this message is not the intended recipient, you are hereby notified that
any review, retransmission, dissemination, distribution, copying or other
use of, or taking of any action in reliance upon this information is
strictly prohibited. If you have received this communication in error,
please contact the sender and delete the material from your computer.