我在名为customer的数据库中有一个表,它具有类似代码和名称的属性。我在其他表格中调用了客户的价值并使用组合框显示。我在组合框中显示了代码,我想要做的是当我在组合框中选择代码时,值'name'可以显示在文本字段中,'name'代表基于代码显示。如何根据Java中的combobox选项设置文本字段值?
这里是我的代码:
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的还必须显示“鲍勃”,因为代码B0001是属于鲍勃。
你能发表一些代码吗? – DLJ
如何命名存储/检索?它是否与您在组合框中放置的值相关联?问题是语言和抽象是可以回答的 – MadProgrammer
你可以使用javascript来做到这一点.. –