Java add a list to class and modification -
i have problem list. adds list class. in class list more items added. when want display list of class not have items.
add people mysqlcategorydao -> modify in mysqlcategorydao -> return people in class model.
public class model { public list<category> people = new vector<category>(); public list<category> getpeople() { (category person : people) { system.out.println(person.getname()); //no data } return new arraylist<category>(people); } public void load() throws exception { daofactory factory = daofactory.getfactory(daofactory.mysql); new mysqlcategorydao(job.select,people).execute(); } }
class in modifies list
public class mysqlcategorydao extends swingworker<void, category> implements categorydao{ private job job; public list<category> list; public mysqlcategorydao(job job, list<category> list){ this.job = job; this.list = list; } @override public void doinbackground() throws exception { // todo auto-generated method stub if(job == job.select){ getcategory(); system.out.println("table selected"); } return null; } public list<category> getcategory() throws sqlexception { connection conn = database.getinstance().getconnection(); system.out.println(conn); string sql = "select id, name kategorie"; statement selectstatement = conn.createstatement(); resultset results = selectstatement.executequery(sql); while(results.next()) { int id = results.getint("id"); string name = results.getstring("name"); ///category category = new category(id, name); //cat.add(category); publish(new category(id,name)); system.out.println("test"); } results.close(); selectstatement.close(); return null; } public void process(list<category> chunks){ list.addall(chunks); (category person : list) { system.out.println(person.getname()); //data show ok! } } }
when want refer list of model did not get.
public void loaddata() { mysqlcategorydao dao = new mysqlcategorydao(null,null); people = model.getpeople(); (category person : people) { tablemodel .addrow(new object[] { person.getid(), person.getname() }); //no data } people.clear(); }
Comments
Post a Comment