Java Beans and Database connection
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
files interact with the databases.
Re: Java Beans and Database connection
"vinod" <email@example.com> wrote:
>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
>files interact with the databases.
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!
DevX Java Pro
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center