Solved

Overriding doGet / doPost method from HttpServlet that throws SQLException

Posted on 2010-08-12
1
1,341 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
ID: 33424884
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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
Modeling a class in java 5 60
throw exception 21 58
jmss example java 2 23
SequenceInputStream example 3 19
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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.

861 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