Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet loading

 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am displaying a drop down list box after fetching values from
the database in a string in this way
while(rs.next())
{
str[i] = rs.getString(col_name);
i++;
}
and putting the values of the
array in list box in this way
for(i=0;i<=str.length;i++)
out.println("<select>");
for(int i = 0; i <= str1.length-1;i++)
{
out.println(" <option value="+str1[i]+">"+str1[i]+"</option>");
}
out.println("</select>");
when i first time load this servlet it shows the database values
in the drop down list box
but as soon as i press refresh /reload of my browser
it puts null values in all array elements
and throws exception array exception null;
Can any one tell me why is it happening so
and how to rectify the problem
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess would be that you are not doing a fresh query when you reload the page, so it's trying to get results past the end of the ResultSet. A ResultSet can only be read once.
The usual way to do this is to read the results into a Vector once, and then populate your servlet output from the Vector.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic