Web Page and Database Design Problem

Ok, so I'm trying to develop an app, but am having a few problems and need some advice/help.

I have a webpage made up of jsp pages. These pages will contain forms that will either list info from the databse, or allow users to enter data to submit to the DB.

So I will have Servelts that will process the form information.

I also have written DAO interfaces for different tables. For example I have a config table which olds keys and there values.

This information will only ever be displayed so I have an interface which getAll() and get(String key).

I want to avoid putting code like below going into the DAO

ctx = new InitialContext();

javax.sql.DataSource ds

= (javax.sql.DataSource) ctx.lookup (dataSource);

conn = ds.getConnection();

PreparedStatement stmt = conn.prepareStatement(query);

ResultSet records = stmt.executeQuery();

I'd prefer to make calls from my DAO getAll() method to another class which would create the connection, and query the db, and return the ResultSet, so that I can store/manipulate it anyway I wish, before passing the results back to the servlet.

Problem is the records seem to come back null!

[1214 byte] By [devdaveja] at [2007-10-2 16:29:02]
# 1

> ctx = new InitialContext();

> javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup (dataSource);

> conn = ds.getConnection();

You should have a Connection Pool to create a connection and hand it out to whoover ask for it.

Check out Hibernate

Hibernate can manger your connection (you need to set the xml configuration first) .. It's another layer to encapsulate your JDBC connection, request, etc..

Also check out Spring Framework. Spring can makes Transaction much more easy to implement (using aspect)

It provides a handful of useful api for you to work with. like JdbcTemplate, HibernateTemplate.

tnguyen1973a at 2007-7-13 17:30:27 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
Cheers, well this code is using a connection pool provided by WebLogic.The param dataSouce is the name of the connection pool.
devdaveja at 2007-7-13 17:30:27 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
Spring is a good answer for this.%
duffymoa at 2007-7-13 17:30:27 > top of Java-index,Other Topics,Patterns & OO Design...