Solved

SQLException

Posted on 2002-04-19
6
304 Views
Last Modified: 2010-05-18
I have a problem of closing a resultset and connection in the catch block.  I close them in the TRY, but the same code does not work in the Catch.


TRY block up here.
---------------------------------------------------------
                                rset.close();
                                call.close();

                        }       // end try

                        catch (SQLException e) {
                                rset.close();//not working
                                call.close();//not working

                        } // end catch


The error reads "EXCEPTION JAVA.SQL.SQLEXCEPTION MUST BE CAUGHT, OR B.(RUN OUT OF SPACE.)  

and then it focuses on reset,close();

I thought I was catching the error?  I'm new and confused.
0
Comment
Question by:scotiaceilidh
  • 3
  • 2
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6955180
The close method defines that it throws a SQLException, so you need to handle this exception inside your catch.
Something like:

}       // end try
catch (SQLException e) {
   try
   {
       rset.close();//not working
       call.close();//not working
   }
   catch (SQLException ex)
   {
       System.out.println(ex);
   }
} // end catch

0
 
LVL 2

Expert Comment

by:coreyit
ID: 6955183
You need to put them in another try/catch block within your catch:

try {
  // other stuff that could throw first exception

  rset.close();
  call.close();
}
catch( SQLException e ) {
  try {
    rset.close();
    call.close();
  }
  catch( SQLException e ) {
    System.out.println( "[debug] couldn't close one of them" );
  }
}

-corey
0
 
LVL 2

Expert Comment

by:coreyit
ID: 6955184
ah, as objects suggested first.

-corey
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 6955186
:-)
0
 

Expert Comment

by:gsvikram
ID: 6988658
It is always better to put all the close() methods in
"finally " block.
Try this one,
try {
// code goes here
         }catch(Exception ex)
          {
               System.out.println(ex.getMessage());
           }
finally {
       rset.close();
       con.close();
    }
vikram
0
 
LVL 92

Expert Comment

by:objects
ID: 6992450
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question