This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Also, if you are using the provided line of code in a JSP, you are probably doing domething that is now discouraged in a JSP, and the operation should be moved to a Servlet, a Context asset (whether servlet or session depends on its purpose), a Bean, or a custom JSTL tag.
Hi, my suggetion is better keep DB related code in servlet. Because it will be executed everytime whenever page gets loaded. Getter connection every time it is bit heavy process and also it is not a good practice.
Hey, please avoid using the scriptlet directly in jsp pages.
As other people menthioned, it is a good idea to wrap the database processing in servlet. However,it really depends on your application.You can use JSTL in jsp pages for small-scale application.You may find "connection pool" is very useful.Do a google search please.
Originally posted by ravinder kopparam: Hi, my suggetion is better keep DB related code in servlet. Because it will be executed everytime whenever page gets loaded. Getter connection every time it is bit heavy process and also it is not a good practice.
I need to ask, why is it better to put the DB initialization info in a servlet? You do not need to initialise the Driver every time a servlet is accessed. If you are not capable of using the Application/Web servers connection pooling, then you would be much better off putting the initialization code into a class that will be executed by a listener when the application starts, and then save the initialized driver (probably in a class with methods for creating connections and doing other DB related tasks) in the application context.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com