代码如下,红色的位置为疑惑的地方,记录可以取到,但是显示出来的结果是一样的,
是不是调用domAccount.size()的方法不对啊?import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import dom.DOMAccount;
import dom.DOMIdType;
import uc.UCQuerytAccountInfo;
import util.Constant;public class UICustomerInfoList extends JFrame {
        /**
         *
         */
        protected DefaultTableModel dtm;
        protected JScrollPane jsp;
        protected Vector<DOMAccount> domAccount;
        protected Vector<String> cell=new Vector<String>();
        protected Vector<Vector<String>> row=new Vector<Vector<String>>();
        protected JTable table;
        protected Vector<String> tableHeadName;        UICustomerInfoList(String sql) {                dtm = new DefaultTableModel();
                String[] tableHeads = { "证件号", "姓名", "性别", "VIP", "账号" };
                tableHeadName = new Vector<String>();
                int j=tableHeads.length;
                for (int i = 0; i <j; i++) {// 用循环控制表头的插入
                        tableHeadName.add(tableHeads);
                }
                domAccount=UCQuerytAccountInfo.queryAccountInfo(sql);
                System.out.println(domAccount.size());
                for (int i=0;i< domAccount.size();i++) {
                        cell.addElement(domAccount.get(i).getIdNumber());
                        cell.addElement(domAccount.get(i).getName());
                        cell.addElement(domAccount.get(i).getSex());
                        cell.addElement(domAccount.get(i).getIsVip());
                        cell.addElement(domAccount.get(i).getAccountNumber());               
                        //取得查询的数据,为什么显示的记录都是相同的??????
                        row.add(cell);
                }                dtm.setDataVector(row, tableHeadName);// 行列加入
               
                table = new JTable(dtm);// tableModel对象加入表对象
                table.setRowHeight(20);// 设置行高
                table.setEnabled(false);
                jsp = new JScrollPane(table);
               
                this.add(jsp);
               
                this.setSize(800, 400);
                this.setVisible(true);
                this.setTitle(Constant.CUSTOMER_INFO_QUERY);
        
                this.setLocationRelativeTo(null);
                this.setResizable(false);
                this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
        }        /**
         * @param args
         */
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                new UICustomerInfoList("select * from account");
        }
}

解决方案 »

  1.   

    在你紅色的地方  把cell  輸出出來看看結果 ~~
      

  2.   

    你的cell在什么地方new 出来的?
    应该是在循环里面,每次取一条记录的时候new一个新的cell吧。
    否则的话你的row里面所添加的实际上都是同一个cell.当然里面的数据都相同,而且可以肯定,所有的数据都是你最后一次添加的那一条!!!建议,仔细对照面向对象思想,向集合框架实例添加数据时候的情况。