pro_jsp thread: Comparing to ways of getting and displaying results...
Hi:
Using Bean advantage: All database logic in bean so it is centralized.
But it really is not decoupled from the page since the code below is
really tied to the hip of the bean. Cons: It is not clear in the page
what you are getting back.
Not using Bean advantages: By using the Resin pool object there is
relatively little code in page. By not using out.println() statements
designers will be less likely to fuss it up. The JSP is decoupled from
needing a bean and knwoing what the bean is doing. Cons: Does not follow
MVC approach so coders may attack me...
Your thoughts?
USING A BEAN
<table align=3Dcenter>
<%
Vector rows =3D stats.getNames();
Vector cols =3D null;
for(int i =3D 1; i < rows.size(); i++) // loop through rows
{%>
<tr>
<%
cols =3D (Vector)rows.elementAt(i);
for(int j=3D0; j<cols.size();j++) // loop through collumns
{%>
<td> <%=3Dcols.elementAt(j)%> </td>
<%}
out.println("</tr>");
}
%>
</table>
USING A BEAN
NO BEAN
<%
ResultSet rs;
DBPool pool =3D DBPool.getPool("SuperPlay");
Connection conn =3D pool.getConnection();
Statement stmt =3D conn.createStatement();
rs =3D stmt.executeQuery("Select * FROM tbl_Teams");
stmt.close();
conn.close();
%>
<table>
<%while(rs.next()){%>
<tr>
<td><%=3Drs.getString("TeamName")%></td>
<td><%=3Drs.getString("TeamID")%></td>
<td><%=3Drs.getString("SportID")%></td>
</tr>
<%}%>
</table>