DAO + my DBUtil + Struts 1.2
Sunday, April 03, 2005
DBUtil is my freely available database utility based on the Jakarta
commons-dbutils. It also includes a database connection pool, which is easily configurable via a db.properties file.
Running Application and Source CodeYou can think of the application I provide in the tutorial as a canonical example of a Struts application + my DAO-like pattern and
DBUtil + a working example of and app using Jakarta commons packages.
You can find online:
My DBUtil + Modified DAO PatternThe approach I describe is DAO-like in the sense that your database interactions are delegated away from your controller classes or business objects to
DBUtil.
Your Action and BO classes don't know nor care how the persistence layer is implemented. More over, the code you need to interact with the database is minimal.
For example, this is what a method to create a new record looks like:
public static void create(DemoVO vo) throws Exception {
DBUtil.update(Constants.POOL_NAME,
propertiesSQL.getProperty(Constants.SQL_CREATE),
new Object[] {vo.getName(), vo.getLastName()});
}
Perhaps someone out there can make use of it - It defenetely has saved me countless hours of coding in the last couple of years.
Comments:
hola Jose, me llamo Fernando, soy argentino pero vivo y trabajo en Italia (soy programador). La verdad es que hoy descubri tu sitio y me gusta mucho, no hay demasiados sitios que traten temas de programacion al nivel que los tratas vos.
Te felicito y seguramente voy a seguir leyendo tus notas.
Fernando Arturi
fernando.arturi@gmail.com
Hi, i've tried out your dbutil but i always get a java.lang.exception when i try to create a query based on parameters different from String...i wonder why...
Anyway congratulations on your site.
Nuno Rodrigues
nunoalexandre.rodrigues@gmail.com