Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java with Oracle - Filling a combo box from a table

Status
Not open for further replies.

daeha

Programmer
Feb 8, 2004
1
GB
I am relatively new to java and I was wondering if any one can a point me in the right direction.

I am trying to create a 3tier application with the user front-end linking directly to a database.
I would like to link 2 separate columns to two separate combo boxes if any one has got any ideas of the best way to do this I would greatly appreciate it

Many thanks
daeha
 
Hi,

Write a simple java bean with 2 var's. When you are reading form the DB add that java object to the ArrayList and return that ArrayList. While filling the Combo boxs iterate the arrayList to fill in the values.

Ex:

public class DropDown {

private String column1;
private String column2;

public DropDown(String column1, String column2) {
this.column1 = column1;
this.column2 = column2;
}

public String getColumn1() {
return column1;
}

public void setColumn1(String column1) {
this.column1 = column1;
}

public String getColumn2() {
return column2;
}

public void setColumn2(String column2) {
this.column2 = column2;
}
}

While Reading form the DB

ArrayList list = new ArrayList
while(rs.next)
{
list.add(new DropDown(rs.getString(1), rs.getString(2)));
}
return list;

In the jsp you can get the list.

Iterator iterator = list.iterator();

while(iterator.hasNext())
{
DropDown dropDown = (DropDown)iterator.next();
out.println(&quot;<option >&quot; +dropDown.getColumn1()+&quot;</option>&quot;);
}

similary for column 2.

Hope this will help you.

Cheers,
Venu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top