I agree that the Statement and the PreparedStatement must be explicitly
closed. But what about the
ResultSet. How come the following piece of code works?

try{
  for(int i=0;i<1000;i++)
   WRes.selectInfoProd(connection,182);
 }catch(Exception e){out.print(e);throw e;};
public static BaseEB selectInfoProd(Connection c,int id) throws Exception{
PreparedStatement ps = null;
InfoProd bean = new InfoProd();
try{
ps = c.prepareStatement(selInfoProd);
ps.setInt(1,id);
ResultSet rs = ps.executeQuery();
if (rs.next()){
bean.setId(id);
bean.setName(rs.getString(1));
bean.setDate(rs.getDate(2));
bean.setDescription(WBNames.readClob(rs,"descr"));
bean.setOwner(rs.getInt(4));
bean.setEditor(rs.getString(5));
}else return null;
return bean;
}catch(Exception e){throw e;}
finally{
if (ps!=null)
ps.close();
}
}

public final static String readClob(java.sql.ResultSet rs, String colName)
throws Exception {
String ret = null;
switch (WBNames.DBSERVER_TYPE) {
case WBNames.DB_SERVER_ORACLE :
java.io.Reader in = null;
java.sql.Clob clob = rs.getClob(colName);
if (clob == null)
return null;
in = clob.getCharacterStream();
char[] c = new char[(int) clob.length()];
int count = in.read(c, 0, c.length);
in.close();
in = null;
if (count == -1) {
c = null;
try {
in.close();
} catch (Exception ignored) {
}
//urmatoarele doua linii modificate de cosmin
//pentru extranet
//throw new WBException(ES_CLOB_READ_ERROR);
return "";
}
ret = new String(c, 0, count);
c = null;
try {
in.close();
} catch (Exception ignored) {
}
break;
case WBNames.DB_SERVER_MSSQL :
ret = rs.getString(colName);
break;
default :
throw new Exception(ES_NO_DB);
}
return ret;
}

Thanks for your prompt answers
Cosmin

Nextnet

----- Original Message -----
From: "Adrian Janssen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, January 29, 2003 1:10 PM
Subject: Re: odd oracle error


> We used to get this too and fixed it by making sure that any Statements
and
> ResultSets we create are explicitly closed in finally blocks. It appears
> that these objects hold a cursor open while they live (one or the other or
> both, not too sure so I manage both).
>
> What we now do in fact is manage them as rigorously as we do transactions
> and anywhere we create either, we immediately start a "try" block and
ensure
> that the they are closed in the "finally"  - this required a bit
> re-architecting to ensure that all the "close" calls could be done in the
> same block of code.
>
> Cheers
> Adrian

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

 http://java.sun.com/products/jsp
 http://archives.java.sun.com/jsp-interest.html
 http://forums.java.sun.com
 http://www.jspinsider.com

Reply via email to