Women in Technology

Hear us Roar



Article:
  Creating a Web Application with Ant and Tomcat 4
Subject:   Good article, maybe, but terrible code
Date:   2003-01-13 08:55:50
From:   anonymous2
I think the AddressDB class is a good example of how NOT to use JDBC in a J2EE environment (such as Tomcat 4). It's ironic that the author mentioned the KISS principle, only to then solve the problem of getting access to a DB connection by a lot of unnecessarily complicated code. The correct solution would be to have used the connection pooling provided by Tomcat, which can be configured in the conf/server.xml file. In the code, all that is needed is to open the connection (using DataSource) at the beginning of a the method, and then close it in a finally block.


Another bad mistake in this class implementation is the "handling" of exceptions, as exemplified by the following code (from AddressDB.java):


catch (SQLException e)
{
this.releaseConnection ();
return 0;
}


Instead of throwing another exception (preferably a RuntimeException), it returns an error code!

Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • Good article, maybe, but terrible code
    2003-01-14 15:48:02  woodp [View]

    Thanks for your comments on DataSource connection pooling.

    Early versions of my example software used exceptions, however I had problems with Tomcat 4.1.12 catching those exceptions. Interestingly the early software worked correctly using the Java Web Services Developer Pack version of Tomcat. I took the exception throwing code out of my software [both to keep things simple, and to get the article out].

    I will look at Tomcat 4.1.18 to see if exception handling has improved.