Here you are going to know about how to retrieve database table values in a loop ie assign each row to a different variable so that you can access it for any operation.
First Create a table in mysql or any database:
Create table no(name varchar(20));
Now write the jsp code as follows to retrieve the values and print it.
<%
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/s2sgateway","username","password");
Statement st=con.createStatement();
String[] namediffer=new String[100];
ResultSet rs=st.executeQuery("select * from no");
int i=0;
while(rs.next())
{
namediffer[i]=rs.getString(1);
out.println(namediffer[i]);
i++;
}%>
So namediffer[0] will hold first value
namediffer[1] will hold second value and so on try this and ask question if any doubt.
Happy coding