开发者

Datechooser for SQL query

I have two tables made in access. O开发者_运维问答ne table (Owner) contains: ownerID, name which owner has. Second table (Cars) contains: CarId, carname, year, ownerID they has relations between carid

In my java program I get from first table OwnerName and put them all into comboBox1

String sql="SELECT * FROM Owner ;";
    ResultSet dane = zadanie.executeQuery(sql);
     while(dane.next()) {
         String  OwnerId = dane.getString("OwnerID");
         String OwnerName = dane.getString("OwnerName");
         if (OwnerId != null) {OwnerId = OwnerId.trim();}
         if (OwnerName != null) {OwnerName = OwnerName.trim();}
         comboBox.addItem(OwnerId);
         comboBox_1.addItem(OwnerName);
     }

When I choose owner I want to have in combobox2 only these cars that have this owner.

Can someone suggest a solution?

I don't know exactly how to write the SQL statement to get that.


select tablename.carname from tablename where ownerID=SelectedOwnerID

To get selected owner id you can, for example, create a map Map<Integer,Integer> and store pairs ComboboxItemNumber -> OwnerId

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜