我想從數據庫中獲取數據並在jtree中顯示。我面臨麻煩的ResultSet顯示下面我的代碼如何在jtree中顯示數據
rs1=DB.Select("SELECT AcCode from tblCoa order by AcCode");
while(rs1.next()){
DefaultMutableTreeNode Catagory=new DefaultMutableTreeNode(rs1.getString("AcCode"));
DefaultMutableTreeNode Catagories=new DefaultMutableTreeNode(rs1.getString("AcCode"));
DefaultMutableTreeNode Catagories2=new DefaultMutableTreeNode(rs1.getString("AcCode"));
DefaultMutableTreeNode Catagories3=new DefaultMutableTreeNode(rs1.getString("AcCode"));
DefaultMutableTreeNode Catagories4=new DefaultMutableTreeNode(rs1.getString("AcCode"));
Catagory.add(Catagories);
Catagories.add(Catagories2);
Catagories.add(Catagories3);
Catagories.add(Catagories4);
DefaultTreeModel dtm=new DefaultTreeModel(Catagory);
this.jTree1.setModel(dtm);
}
你可以把所有的代碼放在一個代碼塊中,並描述你的輸出有什麼問題嗎? – mabe02
private void FillData()引發SQLException ResultSet rs1 = null; rs1 = DB.Select(「通過AcCode從tblCoa命令中選擇AcCode」); (rs1.next()){DefaultMutableTreeNode Catagory = new DefaultMutableTreeNode(rs1.getString(「AcCode」)); DefaultMutableTreeNode Catagories = new DefaultMutableTreeNode(rs1.getString(「AcCode」)); –
DefaultMutableTreeNode Catagories2 = new DefaultMutableTreeNode(rs1.getString(「AcCode」)); DefaultMutableTreeNode Catagories3 = new DefaultMutableTreeNode(rs1.getString(「AcCode」)); DefaultMutableTreeNode Catagories4 = new DefaultMutableTreeNode(rs1.getString(「AcCode」)); Catagory.add(Catagories); Catagories.add(Catagories2); Catagories.add(Catagories3); Catagories.add(Catagories4); DefaultTreeModel dtm = newDefaultTreeModel(Catagory); this.jTree1.setModel(dtm);} –