I just found this problem when I want to full my JTable I have this method that return an arrayList of categories :
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;
}
and here is the categorie class (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 + "]";
}
}
so, I want to full my JTable with this arrayList but the constructor doesn't accept
arrayList<Categorie>
and I tested also :
ArrayList<Contact> listc = ContactDAO.findAll();
Contact[] cs = listc.toArray(new Contact[listc.size()]);
JTable t = new JTable(cs, columnNames);
but it doesn't accept cs
field
do you have any idea
thank you in advance