Hello:
Using
JSP, I'm trying to alternate the <tr bgcolor> when out putting from a database. Using the code below, I am able to out put the data, but the bgcolor stays the same on every row.
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc
dbc:jsptest");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM family");
while (rs.next()){
String familyId = rs.getString("ID");
String firstName = rs.getString("first_name");
String lastName = rs.getString("last_name");
String telephoneNumber = rs.getString("telephone_number");
int swapColor = 0;
if (swapColor == 0)
{
out.print("<tr bgcolor='#f4f4f4'>");
out.print("<td>" + familyId + "</td>");
out.print("<td>" + firstName + "</td>");
out.print("<td>" + lastName + "</td>");
out.print("<td>" + telephoneNumber + "</td></tr>");
swapColor = swapColor + 1;
}
else
{
out.print("<tr bgcolor='#cccccc'>");
out.print("<td>" + familyId + "</td>");
out.print("<td>" + firstName + "</td>");
out.print("<td>" + lastName + "</td>");
out.print("<td>" + telephoneNumber + "</td></tr>");
swapColor = 0;
}
}
con.close();
%>
If anybody can identify my mistake and post a suggestion or solution, I would appreciate it.
Thanks