0

当我想填满我的 JTable 时,我刚刚发现了这个问题,我有这个方法返回一个类别的数组列表:

public static ArrayList<Categorie> findAll() {
    ArrayList<Categorie> list  = new ArrayList<Categorie>();
    try {

        Statement st = connect.createStatement();
        String sql = "select * from categorie ";
        ResultSet rs = st.executeQuery(sql);
        while (rs.next()){
            Categorie tmp = new Categorie(rs.getInt("idcategorie"),rs.getString("description"));
            list.add(tmp);
        }



    } catch (SQLException e) {
            e.printStackTrace();
    }
    return list;

}

这是类别类(POJO):

    package modele;

public class Categorie {
private int idcategorie;
private String description;
public Categorie(){

}
public Categorie(int idcategorie, String description) { 
    this.idcategorie = idcategorie;
    this.description = description;
}
public int getIdcategorie() {
    return idcategorie;
}
public void setIdcategorie(int idcategorie) {
    this.idcategorie = idcategorie;
}
public String getDescription() {
    return description;
}
public void setDescription(String description) {
    this.description = description;
}
@Override
public String toString() {
    return "Categorie [idcategorie=" + idcategorie + ", description="
            + description + "]";
}

}

所以,我想用这个 arrayList 填充我的 JTable,但构造函数不接受

arrayList<Categorie>

我也测试了:

ArrayList<Contact> listc = ContactDAO.findAll();    
Contact[] cs = listc.toArray(new Contact[listc.size()]);
        JTable t = new JTable(cs, columnNames);

但它不接受cs字段

你有什么主意吗

先感谢您

4

0 回答 0