Database connection
hi all,
i m using servletjsp and beans for developing my web application i m using tomcat as my servlet container.
now i want ot connect my application to datbase which in my case in mySQL,my question is there are so many ways to coonect to database in a web application,i want to know the best and efficient method for database connectivity in my case so that it should have all professional aspects like efficiency and the the performance in peak conditions.
any help will be much appriciated.
Thanks,
Umesh
# 1
Well it starts with using Connection pooling. Most java web/application servers have built in support for it, check the documentation of your particular web server.
Next is that you learn how to properly handle business logic like database transactions. You do NOT want to have any database code in a jsp or servlet, you want that logic in seperate classes, usually referred to as a DataAccessObject (DAO). Putting your database logic in such a class makes it so you can reuse those database transactions.
You should also look into how you want to access your database from java. do you want to use low level JDBC, or do you want to use a persistency API like the one built into J2EE, or hibernate. Perhaps you are using a framework like Struts or Spring that has database handling built in?
Want efficiency? optimize your database. Check the performance of your queries and create indexes where needed.