จะดึงข้อมูลจาก Database มาโชว์ใน ComboBox ครับ
public ArrayList<String> ComboBox(){
ArrayList<String> arrList = new ArrayList<String> () ;
MysqlConnect b = new MysqlConnect();
b.connect();
try{
String a = null;
ServiceRate SR = new ServiceRate();
String sql = "Select * FROM servicerate";
PreparedStatement stmt = b.connect().prepareStatement(sql);
ResultSet rs = stmt.executeQuery(sql);
while (rs.next())
{
SR.Supplyname = rs.getString(1);
SR.Supplyrate = rs.getString(2);
arrList.add(a);
}
}catch(Exception ex){
System.out.println(ex.toString());
}finally{
if(b.connect() != null){
b.disconnect();
}
}
return arrList;
}
ส่วนตรง Action ของปุ่มนึกไม่ออกครับว่าจะเขียนอะไรดี
private void FillComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
ServiceRate SR = new ServiceRate();
SR.ComboBox();
}
งงมากๆ ครับรบกวนช่วยทีครับ
รบกวนช่วยดู Code Java หน่อยครับ
public ArrayList<String> ComboBox(){
ArrayList<String> arrList = new ArrayList<String> () ;
MysqlConnect b = new MysqlConnect();
b.connect();
try{
String a = null;
ServiceRate SR = new ServiceRate();
String sql = "Select * FROM servicerate";
PreparedStatement stmt = b.connect().prepareStatement(sql);
ResultSet rs = stmt.executeQuery(sql);
while (rs.next())
{
SR.Supplyname = rs.getString(1);
SR.Supplyrate = rs.getString(2);
arrList.add(a);
}
}catch(Exception ex){
System.out.println(ex.toString());
}finally{
if(b.connect() != null){
b.disconnect();
}
}
return arrList;
}
ส่วนตรง Action ของปุ่มนึกไม่ออกครับว่าจะเขียนอะไรดี
private void FillComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
ServiceRate SR = new ServiceRate();
SR.ComboBox();
}
งงมากๆ ครับรบกวนช่วยทีครับ