0

I have the following code:

 <%
            for (int i = 0; i < rs.getFetchSize(); i++) {
                System.out.print("test");
                //blah
%>
        <div id="Test<%= out.print(i) %>">
            <div class="<%= oddOrEven(i)%>Header">
                <div class="<%= oddOrEven(i)%>A">Test<% out.print(i);%></div>
                <div class="<%= oddOrEven(i)%>B"> 
                //Stuff here

Odd or Even simply responds with the word odd or even based on the number i passed to it, that should make my css style alternate between grey colors.

When I compile the page it works, but this part is totally omitted and doesn't appear in the source. Can someone help me get this working?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
A_Elric
  • 3,508
  • 13
  • 52
  • 85

2 Answers2

3

The ResultSet#getFetchSize() doesn't return the amount of returned records as you seemed to expect. It just returns the configured fetch size. It may for instance just return 0 depending on the JDBC driver configuration and semantics.

Just use ResultSet#next() the usual way to move the cursor to the next row.

for (int i = 0; rs.next(); i++) {

That said, writing Java code in a JSP file is officially discouraged since a decade. I'd suggest to work on that part as well.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

How about this:

<%
for(int i = 0; i < rs.getFetchSize(); i++)
{
%>
<div id="Test<%= i%>">
  <div class="<%= oddOrEven(i)%>Header">
     <div class="oddOrEven(i)A">Test<%= i%></div>

<%
}
%>

You are missing a last curly brace which will complete the for loop

Also you do not need to provide ... out.println() ... <%= %> will do that for you

jsshah
  • 1,741
  • 1
  • 10
  • 18