首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

为何点击jbutton, jtable会有两遍数据,而且第二遍都是空值

2013-07-09 
为什么点击jbutton, jtable会有两遍数据,而且第二遍都是空值为什么点击jbutton 做查询功能 jtable会有两遍

为什么点击jbutton, jtable会有两遍数据,而且第二遍都是空值
为什么点击jbutton 做查询功能 jtable会有两遍数据,而且第二遍都是空值,而且每点击一次都会增加两遍数据, 这是为什么呢??????

贴了部分代码,不知道有没有人知道为什么?

这个是jbutton的相应事件



 private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
       tableModel=new DefaultTableModel(entity.searchCustomer(getName() ), getTitles());
       //System.out.println(entity.searchCustomer(getSearchCustomerName() ));
        
        jTable1 = new javax.swing.JTable(tableModel);
        jScrollPane1.setViewportView(jTable1);

    }//GEN-LAST:event_jButton1MouseClicked

    public Vector getTitles() {
        titles.add("id");
        titles.add("name");
        titles.add("age");
        return titles;
    }

    public String getName() {
        return new String(jTextField1.getText());
    }      



这个是调用查找的方法


  public Vector searchCustomerInfo = new Vector();
    public Vector searchCustomer(String name) {
        String sql = "select * from users_xiey where name like'%" + name + "%'";
        //  System.out.println(sql);
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        //  Vector rowData = new Vector();
        try {
            conn = ConnectionUtils.getConnection();
            stmt = conn.createStatement();
            rs = stmt.executeQuery(sql);

            while (rs.next()) {


                 Vector vcRows = new Vector();
                vcRows.add(rs.getString("id"));
                vcRows.add(rs.getString("name"));
                vcRows.add(rs.getString("age"));
                searchCustomerInfo.add(vcRows);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            ConnectionUtils.close(rs);
            ConnectionUtils.close(stmt);
            ConnectionUtils.close(conn);
        }
        return searchCustomerInfo;

    }




下面截个图:
为何点击jbutton, jtable会有两遍数据,而且第二遍都是空值


再点击ok按钮后,数据查找显示出来了,但是列名id name age出了两遍,而且第二遍是空的,这是为什么啊为何点击jbutton, jtable会有两遍数据,而且第二遍都是空值


[解决办法]
列名出现了两次,数据没出来,这样的话应该是你布局的时候出现错误了,跟sql语句没关系。你看下你的窗口布局。

热点排行