Solved

Overriding doGet / doPost method from HttpServlet that throws SQLException

Posted on 2010-08-12
1
1,315 Views
Last Modified: 2013-11-24
As you know, both doGet and doPost from HTTPServlet throw ServletException and IOException. I created a class that extends HttpServlet and overrides doGet and doPost method, but I need these methods to throw SQLException in addition to ServletException and IOException. I understand that the concept of "overriding" includes overriding exceptions to be thrown, but is there any way I can throw SQLException from doGet and doPost?
0
Comment
Question by:shepp_it
1 Comment
 
LVL 10

Accepted Solution

by:
Hegemon earned 500 total points
Comment Utility
Your overridden methods must comply with the contract defined by HttpServlet methods. You cannot declare any checked exceptions in the throws clause of your methods other than HttpServletException, IOException or their subclasses.

Thus the only ways to throw your SQL exception are:

1. Wrap it as a cause into an HttpServletException or IOException and throw one of them.
2. Wrap it as a cause of a RuntimeException and throw it.
3. Throw an SQLException where you want to but catch it and either handle or rethrow as in pp. 1 or 2.
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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

762 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

6 Experts available now in Live!

Get 1:1 Help Now