I am creating a simple blogging website just as a learning project using Java servlets on Tomcat.
There will be two pages:
- first page is a form to enter the subject and text for the blog, inserts them into a MySQL database using JDBC.
- second page is a page which fetches data from the database and displays it.
I was wondering if instead of opening and closing the JDBC database connection in each page separately, I should create a separate class which keeps a connection open.
However, I don't want to instantiate it, and don't want to make it static.
Is there a way to do this?
Also, is it a good practice and is it safe to keep a database connection open as long as the server is running?