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

[327 byte] By [girishchalke002a] at [2007-10-3 8:17:15]
# 1
If U r instrested in industry standards..I wud ask U to follow MVC 2.0 Patterm ....Wid model to Be a combination ofBIZ LOGIC + BIZ DELEGATE + DAO
RahulSharnaa at 2007-7-15 3:22:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

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

gimbal2a at 2007-7-15 3:22:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
I have came across many examples in the this forum , and found that many JSP codes are using database connectivity using java.sql directly.... question is how this code type of code affect the performance of the application.
girishchalke002a at 2007-7-15 3:22:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

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)

evnafetsa at 2007-7-15 3:22:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
thx,My entire web application is in JSP only , and i am satisfy with the performance as far as database connectivity is concern.Thx for the repliesGirish..
girishchalke002a at 2007-7-15 3:22:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...