1

Currently I'm creating the DB connection again and again in every JSP/Servlet. I would like to reuse my DB connection in my JSP/Servlet project. How can I achieve this?

4

1 Answer 1

6

The "correct" way to do this is to make use of connection pooling. That way the overhead of creating / closing connections is reduced.

Apart from that there's is nothing wrong with the way you are doing things. Maintaining open connections for too long is generally not a good idea.

To make this less hassle - you can create a utility class which returns a connection from the pool and likewise has a method for returning the connection to the pool.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.