ORA-01000: maximum open cursors exceeded I know it but !!!!

I know why this exception is generated, but I can not go through all the code and figure out where the connections, statements and resultsets are not properly closed because I had been given a task to figure out some one else's problem and the code is composed of 736 jsp and couple of hundred servlets , so it is almost impossible to go through all the statements..

Please tell me some trick or tip by which i could fix this bug with minimum effort....

Some chunks of code are as follows...

<%

conn.ConnectDB();

ResultSet rSet =null;

String sqlQuery2 ="select * from client_configuration ";

rSet = conn.executeQ(sqlQuery2);

try{

while(rSet.next()){

%>

<tr>

<td>

<%=rSet.getString(1)%>

</td>

<td>

<%=rSet.getString(2)%>

</td>

</tr>

<%

}

}catch(SQLException ex){

System.out.println("Exception in test123.jsp"+ex);

}finally{

conn.closeStmt();

conn.CloseCon();

}

> ConnectDB()

publicvoid ConnectDB()

throws SQLException, Exception

{

rb = ResourceBundle.getBundle("HDConn.app");

String s = rb.getString("pwd");

String s1 = rb.getString("uname");

String s2 = rb.getString("ip");

String s3 = rb.getString("sid");

String dataSource = rb.getString("DataSource");

try

{

Context initialContext =new InitialContext();

// DataSource datasource = (DataSource)initialContext.lookup("jdbc/KFHD01PooledDS");

DataSource datasource = (DataSource)initialContext.lookup(dataSource);

if(conn ==null)

{

conn = datasource.getConnection();

++counter;

System.out.println("Counter = "+counter);

}

}catch(NamingException ex )

{

thrownew RuntimeException("Init: Cannot get connection " + ex);

}

}

publicsynchronized ResultSet executeQ(String s)

throws SQLException

{

Object obj =null;

ResultSet resultset =null;

try

{

if(conn.isClosed())

ConnectDB();

stmt = conn.createStatement();

resultset = stmt.executeQuery(s);

}

catch(Exception exception)

{

System.out.println(exception);

}

return resultset;

}

publicvoid CloseCon()

{

try

{

if(rset !=null)

{

rset.close();

rset =null;

}

if(!conn.isClosed())

conn.close();

}

catch(Exception exception){}

}

publicvoid closeStmt()

{

try

{

stmt.close();

}

catch(Exception exception){}

}

your help will be greatly appreciated...

[5236 byte] By [ali_hammada] at [2007-11-27 9:39:31]
# 1

You should be able to find a connection pool that will automatically close open resources after some fixed time-out period.

Note that this is a hack - but if it's really impractical to fix the real problem, it should be an approach that will give you some measure of stability.

You might also want to take a steel ruler to the fingers of the person who created the code in the first place :-)

dcmintera at 2007-7-12 23:15:04 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Thank you very much for your quick reply....

I have some more to say....Please tolerate my ignorance

how can i find the connection pool.. i have never used datasource before to get connection .. this the first time ...

ive used the following code to get connection from datasource

Context initialContext = new InitialContext();

DataSource datasource = (DataSource)initialContext.lookup(dataSource);

conn = datasource.getConnection();

Is there any thing wrong with it? if yes, then how can i improve it...

I m using JDeveloper 10.1.2 and oracle 10g

your quick help will be greatly appreciated

ali_hammada at 2007-7-12 23:15:04 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

That's fine - what you do is specify the connection pool implementation to use when you're configuring the datasource in the first place; it's not something you need to worry about in the client implementation.

The specifics of configuring it will depend upon your application server and upon the connection pool implementation that you elect to use - you'll need to talk to your vendor about that.

dcmintera at 2007-7-12 23:15:04 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
Generally you can define and configure datasources in the administration console of your applicationserver.
BalusCa at 2007-7-12 23:15:04 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...