Solved

Overriding doGet / doPost method from HttpServlet that throws SQLException

Posted on 2010-08-12
1
1,349 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
[X]
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
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: 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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HashMap Vs TreeMap 12 68
java stored proc example 9 58
Java: The Public Class Main 4 45
hashmap order 17 42
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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.

733 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