Thanks in advance for giving attention. Here i am having good idea about mvc pattern of jsp servlet and jdbc as beginner. My scenario is
- mysql table employee so pojo class Employee
- EmployeeDao for dao operations
- Service class for authentication of login & other services
- Servlet to fetch data from jsp page and calling service
Now i am not sure about best way to create connection where i found some ideas below,
- creating jdbc connection in EmployeeDao constructor by loading driver. Service for creating dao object and perform operations and then clearing connection using same object's method destroy to close connection.
- loading driver and creating connection at init() method of servlet? if so, then do i need to pass connection object created in init to service so it will pass dao further? And destroy() of servlet will be used to close connection.
- Using ServletListener or ServletContextListener ( not having brief idea about these ( needs some documents for study)
Till now I was using Dao class for connection and loading driver but i need to optimise it and make my application efficient. Correct me if I am misleading somewhere. thanking you