tomcat - Database Connection Pooling in Java Servlets -


i'm creating web application employee management system, using: apache tomcat http server, oracle database, applets client side programming , servlets server side programming. want use dbcp manage connections database.

i servlet performing queries use username , password entered client connection. far i've seen username , password connection pool must set when configuring resource in context.xml.

is there way achieve , still use dbcp? or have open connections in doget() , dopost() every request?

as mentioned in comments, normally, restriction logic done on application side not database side.

but if want use db security model need create seperate datasource (connectionpool) each logged user , store in session. if have many concurrent access discover running out of resources.

for example using datasource easier configure may use connection pool implementation.

in login action create new datasource, (for example using apache common: http://commons.apache.org/proper/commons-dbcp/) , insert session

basicdatasource ds = new basicdatasource(); ... ds.setpassword(userpassword); ds.setusername(login); ...  httpsession session = request.getsession(); session.setattribute("dbcon",ds); 

and in other gets/posts:

httpsession session = request.getsession(); datasource ds = (datasource)session.getattribute("dbcon"); 

since going 1 datasource per user, make sure use low parameteres of pool, example size=3, should enough user.


Popular posts from this blog