This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, I was reading some of the latest posts and I found this one: http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=7&t=007630 here, it uses a bean to make a connection to a database. Then you have a servlet that receives some parameters and perform a particular task using the bean. My question is: What is the best practice, to have all the process of connecting to a database in a servlet or JavaBean..? thanks
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
The best implementation of this is to have one class that both your servlets and jsp's have access to for each table in your database with variables corresponding to each field in your database. Each time you need access to the database, use only this class. That way, you can synchronize on that class and you'll never have to worry about having bad data, especially when adding new data or updating. Just doing selects, it isn't as big of a deal, but it is still much more managable having just one class that both servlets and the jsp has access to.