Iam finding difficulty in giving connections to MySQL database from JSP file...Anyone please provide this class.
This is not working .. Any alternate solutions? Please...
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.
Originally posted by Niranjana Nagaraju:
I am finding difficulty in giving connections to MySQL database from JSP file...
your provided information is not enough to understand. Please provide me some details where you find difficulty in your jsp code in order to help and solve your problem..
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:
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.