ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
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!


1 to 1 of 1
1 to 1 of 1