DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    vinod Guest

    Java Beans and Database connection


    Hi,
    Is there any way by which i can keep my database connectivity in a JavaBean

    and make use of this connection in multiple JSP files.
    i.e a connection to database is done once and using this connection many
    JSP
    files interact with the databases.

    Regards.

  2. #2
    Kyle Gabhart Guest

    Re: Java Beans and Database connection


    "vinod" <vinodvishwa@yahoo.com> wrote:
    >
    >Hi,
    >Is there any way by which i can keep my database connectivity in a JavaBean
    >
    >and make use of this connection in multiple JSP files.
    >i.e a connection to database is done once and using this connection many
    >JSP
    >files interact with the databases.
    >
    >Regards.


    Hello!

    The short answer to your question is 'No'. The longer answer to your question
    is 'sorta'. There's a couple of ways you could go about this. Depending
    upon why you want to do this, the answer could be as simple as connection
    pooling. You could take advantage of a JDBC driver that implements connection
    pooling, or even roll your own connection pooling mechanism. You could write
    your own Connection Manager that only created a single connection and farmed
    out a reference to that connection whenever a JavaBean requested one.

    The second solution would be to use a servlet that implements the SingleThreadedModel
    interface and have it maintain a reference to the Connection object. Then
    you could simply have your JSP grab the reference and pass it to the JavaBean.

    With a little more information as to what you are trying to do, I could give
    you more specific directions.

    I hope this is helpful. Happy Coding!

    Cordially,

    Kyle Gabhart
    DevX Java Pro



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links