mysql populate 操作,如何使用来自mySQL数据库的信息填充jcombobox?

Basically the program takes customer information and dumps it in a database.

In order to change information I want the user to be able to pick a customer name

from a combobox, so the system can then call all the info out of the database on that customer. Accessing the database is fine, putting info in and changing it is fine.. I just cant figure out how to get the combobox to populate with all the customer names.

解决方案

The simplest solution is to create an array of String from the database. Then use that to create the combobox.

String[] mydbStrings = .....;

JComboBox mycombo = new JComboBox(mydbStrings);

But that will give you only some strings. It may be better to define a class that represents the customer, load the customers from the database, ensure that an adequate toString() is defined in the Customer class and create an array of Customers that is used in the Combo Box. That way, the customer names are displayed in the combobox but hwen you select one you have all the customer details readily available.

If you think this is too memory intensive to load all your customer's data at once it is possible to create a smaller custInfo class with just the name and ID. Then use that in the combobox and load the rest of the customer data after it is selected.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值