|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
Hi,
I have a problem in maintaining the open database connection objects in servlets. How to do this? Once, i connect to the database from one servlet or page. It should be opened for all the servlets which uses sql statements. Every servlet or page should not make a new connection. Vijaya. |
|
#2
|
|||
|
|||
|
hi there,
you can create a connection in one servlet.. then put in into ServletContext. e.g. In "AServlet.class" : Connection con = ..... ServletContext sc = getServletConfig().getServletContext(); sc.setAttribute("con", con); and in "BServlet.class", you can retrieve this connection by doing: Connection con = null; ServletContext sc = getServletConfig().getServletContext(); con = (Connection)sc.getAttribute("con"); and do whatever you want in "BServlet.class". try it... it'd better to create a ConnectionPool class to give out connection... therefore each servlet will get their own connection and return it back to the ConnectionPool once they finish. good luck. -hoi. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Database Connectivity in Servlets |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|