#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    0
    Rep Power
    0

    Angry


    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.

    Comments on this post

    • Gran Roguismo agrees
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Location
    NY
    Posts
    0
    Rep Power
    0

    Smile try to put the


    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.

    Comments on this post

    • Gran Roguismo agrees

IMN logo majestic logo threadwatch logo seochat tools logo