Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQLException

Posted on 2002-04-19
6
Medium Priority
?
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 92

Accepted Solution

by:
objects earned 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

721 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