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
Solved

SQLException

Posted on 2002-04-19
6
305 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat not starting 6 68
How to determine if a string is a valid SHA value 7 35
Java: anonymous class 4 29
Is there a simpler dropbox system? 10 34
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

828 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