Hi, A ResultSet object is automatically closed when the Statement/PreparedStatement object that generated it is closed.
Best Wishes Shyam Sankar S. ------------------------------- EYME Technologies Technopark, Trivandrum Ph: 91-471-2700064 Cosmin Cremarenco <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Sent by: "A mailing cc: list for discussion Subject: Re: odd oracle error about Sun Microsystem's Java Servlet API Technology." <SERVLET-INTEREST@JA VA.SUN.COM> 01/30/2003 08:57 AM Please respond to "A mailing list for discussion about Sun Microsystem's Java Servlet API Technology." 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, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html ______________________________________________________________________ The information contained in this communication is intended solely for the use of the individual or entity to whom it is addressed and others authorized to receive it. It may contain confidential or legally privileged information. If you are not the intended recipient you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this information is strictly prohibited and may be unlawful. If you have received this communication in error, please notify us immediately by responding to this email and then delete it from your system. Ernst & Young is neither liable for the proper and complete transmission of the information contained in this communication nor for any delay in its receipt. ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html