Link to home
Create AccountLog in
Avatar of Angus
AngusFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Java Database Connections in Web Applications

Hi,
I am developing a web application and I am struggling how to structure the application for database connections.

In short, the application (Java JSP usig Tomcat) and there are numerous Java Classes that will be connecting to the database.  That said, I wish to:

1) Centralise/control the connections of the database:  Therefore ensure that the number of connections to the database is controlled and managed

2) Centralise the logic for:
      - Connection Management - establishing/openning and closing the connections
      - Statement Management - establishing statements and closing statements
      - ResultSet Management - executing statetments and reading the resultset.

So.... in short - I am looking to simpify the application as well as reduce the development effort.

Can any provide some advice on how to solve the above.  Sure this is not new problem?

Regards
A
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Use a connection pooling DataSource such as dbcp

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Angus

ASKER

CEHJ,

Thanks for your prompt response.  I have gone through the example and indeed it is excellent.  In the example the centralise the database connection, however the code for statements and result sets are not centralised.  Is this standard?  Am I asking too much by thinking that the Statement and ResultSet management methods can be centralised?  

Cheers
A.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
>>Is this standard?  

The tendency these days is to higher and higher levels of database abstraction. Have a look at something like Jackrabbit:

http://jackrabbit.apache.org/
Avatar of Angus

ASKER

Thanks.

I think I will opt of the simple approach and simply consolidate the connection management and as for the statement and result sets - I will leave the code in the respective classes.  I.e. not go for DAO or jackrabbit - it is not that I think those options are good.  But for the application that I am developing, I am quicker to put the code the respective classes than try something completely new.

Thanks again for your help.  As always - very impressed with Experts Exchange!!!!  Don't know what I would do without it.