In order to guarantee the statements (and corresponding resultset objects)
close, try the following design pattern:


  try {
     Connection c = ic.lookup(...);

     try {
        Statement stmt = c.createStatement();

        try {
           .. perform your database processing here...

        }
      finally {
         stmt.close();
      }
    }
    finally {
       c.close();
    }
  }
  catch ( Exception ex ) {
     .. exception processing ..
  }


Note that this pattern will guarantee the statement will close even if an
exception is thrown during processing.


Jonathan Baker
Internet Applications Division
Sybase, Inc.



Tom Jansto wrote:
>
> see inline
>
> tom jansto
> [EMAIL PROTECTED]
>
> "For by grace are ye saved through faith, and that not of yourselves;  It is
> the gift of God, not of works, lest any man should boast."
> Ephesians 2:8-9
>
> -----Original Message-----
> From: Prateek Asthana [mailto:[EMAIL PROTECTED]]
> Sent: Friday, November 10, 2000 4:40 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Max Open Cursors Exceeded
>
> Hello Harish,
> I have a few more queries (already mailed to EJB mailing List) which can u
> please answer them. Well correct me if i am wrong.
> 1. I thought the cursors get open only after a we fire a query resulting in
> some records being obtained. Now do the cursor also gets open just by
> preparing a statement?
>
> i have seen no evidence in oracle 8i (8.1.6) of this.  preparing the
> statement doesn't cause the execution plan in oracle to form a cursor
> (whether explicit or implicit), until the statement is executed.
>
> 2. Also if i opt to do ResultSet.Close() and not Statement.Close() then the
> cursor will still get closed or still remain open until Statement.close() is
> executed?
>
> the tests i have run over the last 3 days show me that the statement object
> needs to be explicitly closed.
> i have tried both a thin and thick driver, and have found that the cursors
> in oracle 8i (8.1.6), whether implicit or
> explicit, do not get closed unless the statement object itself is closed.
> ResultSet.close() does not, no matter what the current docs state.  i
> believe that ResultSet.close() does allow the local java ResultSet object to
> be marked for garbage collection, but i haven't verified that as yet.
>
>     Thanking you in advance.
>
> Regards,
> Prateek.
>
> Regards,
> Prateek.
>
> ----- Original Message -----
> From: Harish S K <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, November 10, 2000 1:16 AM
> Subject: Re: Max Open Cursors Exceeded
>
> > You must close the Statement too.
> >
> > -----Original Message-----
> > From: Prateek Asthana [mailto:[EMAIL PROTECTED]]
> > Sent: Saturday, November 11, 2000 12:01 AM
> > To: [EMAIL PROTECTED]
> > Subject: Max Open Cursors Exceeded
> >
> >
> > Hello Friends,
> >     I am getting Max Open Cursors Exceeded Exception. I am making and
> > closing Connections to my Oracle database from my Session Bean. The code
> > is
> > given below:
> >
> > func()
> > {
> >         conn = ds.getConnection();
> >         conn.setAutoCommit(false);
> >         Statement stmt;
> >         try
> >         {
> >             stmt = conn.createStatement();
> >             stmt.executeUpdate(sql);
> >         }
> >         catch (Exception sql_ex)
> >         {
> >              conn.close();
> >        }
> >
> >         try
> >         {
> >             conn.close();
> >         }
> >         catch (Exception conn_ex)
> >         {
> >         }
> > }
> >
> > Now as seen above I am not closing my Statement object by doing
> > stmt.close(). Also in some other section of my program i am obtaining a
> > Result Set. But at the end I am only closing the Connection and not
> > closing
> > the ResultSet. Will this lead to Max Open Cursors Exceeded Exception? Is
> > it
> > not that only closing the Connection Object by calling conn.close() even
> > closes the cursors.
> >
> >     Thanking in advance.
> >
> > Regards,
> > Prateek
> >
> > ========================================================================
> > ===
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> > body
> > of the message "signoff EJB-INTEREST".  For general help, send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
> >
> >
> ===========================================================================
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> > of the message "signoff EJB-INTEREST".  For general help, send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to