JSP and SQL Queries
Hello,
If a JSP application needs Database connectivity to display some values, what is the best approch for the same.
1. Using SQL connections with resultset
2. Using Java Class and using the same in JSP.
3. any other?
what is the industry standard for the same.
Thnx,,
Girish
JSP's are used to display a view (such as a user interface or a report). Database connectivity is business logic and you don't do business logic in JSP's. I would create a servlet to handle business logic and then put the database logic in seperate classes that you can call from the servlet. Then use a JSP with JSTL to display the results of the database query. Putting the business logic in seperate classes makes it reusable.
Frameworks such as Struts, Spring, JSF, etc. work in similar ways, so I guess you can call it an "industry standard". In software development there is no such thing however, you develop to solve a problem, not to follow standards.
If you want to do it this way I suggest you lookup these two things:
1) how to make servlets and JSP's work together
2) the Model View Controller pattern
In terms of performance there is not much difference between writing code in a JSP vs writing it in a servlet.
There is a BIG difference in maintainability though.
I've always been a fan of putting SQL code into beans, because it is more readable, more testable, and more reusable that way.
In terms of performance, your web-app should be using connection pooling (in most cases provided by the container) rather than opening a new database connection on every request (which I see a lot of naive code doing)