Is it valid?

Discussions

General J2EE: Is it valid?

  1. Is it valid? (2 messages)

    Is it valid to lookup a resource (db connection) in the init() method of a servlet?

    Cheers
    Srini

    Threaded Messages (2)

  2. Not a ideal suggestion[ Go to top ]

    Hi Srini,
                When you are developing an tier-architecture, you should not look up a database resource in the servlet, since a web tier should not access the db directly. Insteas you can have a business method in the appliation server which meets ur purpose. This is the ideal way to do, but i'm not sure whether your architecture is having app server or not?

    Cheers
    Rafi
  3. Not a ideal suggestion[ Go to top ]

    Rafi was right on a 3 tier application.
    But if you don't have a middle tier in your application then ..
    Yes. Using the init method to lookup the DB conn is a good way as that is the method first called in the life cycle of a servlet and during the life time it will not be changed.

    Another good strategy would be ti initializa a pool of DB connections rather than a single one. This will give better performance.
    Again initializing the pool can be done in the init() method()

    More:
    http://www.developer.com/tech/article.php/626431
    http://www.javaworld.com/javaworld/jw-10-2000/jw-1027-pool.html

    good luck!

    -vaheesan selvarajah