This is a question I have for a long time. For a db access method, normally we have the structure of:
Is there a way to clean up th code for the last catch block which is for the db clean up exception? Or do I have to write such block in each db call? [ April 21, 2006: Message edited by: Yuan Ye ]
Yuan, A common approach is to create a DBUtils class that has the common code in a static method. Then you can pass the connection/statement/resultset into that method. So one call is repeated instead of a bunch of code.
Another common solution to avoid writing the same dull jdbc code over and over is to use Spring JDBC, a part of the Spring framework. It neatly encapsulates all of the plumbing (connection management, exception handling, looping through result sets, resource cleanup etc.) and lets you focus on the important stuff.
Admit nothing. Blame everyone. Be bitter.
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad: