Solved

Overriding doGet / doPost method from HttpServlet that throws SQLException

Posted on 2010-08-12
1
1,330 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 62
eclipse shortcuts 9 54
hibernate jars 4 28
mysql jsp example issue 32 32
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.

786 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