【发布时间】:2014-01-10 04:04:35
【问题描述】:
我在数据库中有一个名为 customer 的表,它具有代码和名称等属性。我在其他表中调用了客户的值并使用组合框显示它。我已经在组合框中显示了代码,我想做的就是当我在组合框中选择代码时,值'name'可以显示在 text-field 中,'name' 根据代码出现。
这是我的代码:
try {
Connections con = new Connections();
con.setConnections();
String sql = "select * from customer";
Statement stat = con.conn.createStatement();
ResultSet rs=stat.executeQuery(sql);
while (rs.next()){
cmb_custCode.addItem(rs.getString("custCode"));
txt_custName.setText(rs.getString("custName")); // i'm confused in here, how can i call the name based on the code
}
}
catch(Exception e){
e.printStackTrace();
}
}
例如:
当在组合框中选择代码“B0001”时,Jtextfield 也必须显示“Bob”,因为代码 B0001 属于 Bob。
【问题讨论】:
-
你能发布一些代码吗?
-
如何命名存储/检索?它是否与您在组合框中放置的值相关联?问题是用语言和抽象来回答
-
你可以使用javascript来做到这一点..
-
@jack,你从来没有使用过
str变量。 -
@jack 我看到你说你已经解决了这个问题。请分享你的答案。你来这里寻找答案,如果你来了,你应该完成这个。
标签: java swing combobox jtextfield