There is a simple web application that includes several servlets, each of which connects to a database, creates a model and displays it through jsp. I would like to optimize work with the database by working with Java objects instead of tables. For example, if you need to get a bus with a specific id from the bus table, instead of connecting the database, we get the bus object from the hash table, which will work many times faster.
I thought of implementing this way: save the data in the tables. B. in objects at the first connection, then work with these objects, and in the case of a change in b.d. change objects and tables.
I do not know how to create such a class "database", which would store all the data without being deleted from memory when the servlet is finished. I would like to know how this can be done. Thank you in advance.