我在access中创建了两个表。一个表(所有者)包含:ownerID,所有者拥有的名称。第二个表(Cars)包含:CarId,carname,year,ownerID它们之间有carid之间的关系
在我的java程序中,我从第一个表OwnerName中获取并将它们全部放入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);
}当我选择owner时,我希望在combobox2中只有这些拥有此owner的汽车。
有人能给出一个解决方案吗?
我不知道如何编写SQL语句来实现这一点。
发布于 2011-07-14 18:23:01
select tablename.carname from tablename where ownerID=SelectedOwnerID例如,要获取所选所有者id,可以创建地图Map<Integer,Integer>和存储对ComboboxItemNumber -> OwnerId
https://stackoverflow.com/questions/6691616
复制相似问题