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.
String namediffer=new String;
ResultSet rs=st.executeQuery("select * from no");
So namediffer will hold first value
namediffer will hold second value and so on try this and ask question if any doubt.