Solved

SQLException

Posted on 2002-04-19
6
309 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

627 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