Solved

SQLException

Posted on 2002-04-19
6
302 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
Comment Utility
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
Comment Utility
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
Comment Utility
ah, as objects suggested first.

-corey
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 92

Accepted Solution

by:
objects earned 50 total points
Comment Utility
:-)
0
 

Expert Comment

by:gsvikram
Comment Utility
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
Comment Utility
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now