• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ListBox Display

 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a jsp page that has 2 listboxes the first one is a list for the user to choose from and works fine. The second one is a list from a database. I have taken the resultset and put it into an array but I keep getting the last element in the array. Can someone take a look at my code and tell me what I am doing wrong? I am just not seeing it. Thanks!

ArrayList language = new ArrayList();
String lang = "";
List list = new ArrayList();
String s = " ";
try{

ResultSet rs = statement.executeQuery("Select partid, language from partDB.test "
+ "where partid = '" + pid + "' ");
while (rs.next()) {

language.add(rs.getString("language"));

for (int i = 0; i < language.size(); i++) {
String LString = language.get(i).toString();
lang = lang + LString.trim() ;
}

s = (rs.getString("language")); list.toArray(new String[list.size()]);


} }


<td><select size="10"
id="selectedOptions"
name="Selected Language(s)">
<option value='<%=s%>'><%=s%></option>
</select>
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're going to perform the database call from the JSP, why not just build the string while you're looping through it?

 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hadn't considered it, I will give it a try..
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben,
I tried the little code snippet you sent but it doesn't seem to like the option line, can you tell if my syntax is correct?


StringBuffer options = new StringBuffer();
ResultSet rs = statement.executeQuery("Select partid, language from partDB.test "
+ "where partid = '" + pid + "' ");
while (rs.next()) {
options.append("<option value=\"" + rs.getString("language") + "\"> + rs.getString("language") + </option>\n ");
}
%>
<select name="NAME"> <%=options.toString()%>
</select>


Thanks!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The close option tag is not quoted:
..rs.getString("language") + "</option>\n ");


PS: if you use the Code Button when posting in this forum, it will be easier for others to read your code (indents will be preserved).
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Missing a quote here too
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much Ben, it is appearing correctly and so much easier then the extra step of the array. Sorry about the code format, I will remember to use the code button next time.
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Our posts crossed, yes, I discovered the missing quote to.. Thanks again!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic