日期:2014-05-20  浏览次数:20631 次

好几天都没头绪,查询按钮在jtable显示问题???
大家帮我看看把,我想做出个功能,jtable已经显示出了数据库的所有数据,当点击这个查询按钮搜到一条记录,而这时jtable只显示这一条记录。我的jtable只能显示全部数据,点击查询button一点反应都没有,我贴了我的代码,大神们帮我看看是不是哪里写错了,哪里需要改一下的


private void initComponents() { //这个是我的jtable
Vector titles=new Vector();
       titles.add("id");
       titles.add("name");
       titles.add("location");
       titles.add("address");   
       titles.add("postcode");
       titles.add("linkman");
       titles.add("fixphone");
       titles.add("telephone");
       titles.add("remark");

if(i==0){ //我设定了个按钮标签,当i==0时,按钮没点击,执行getCustomerInfo();方法,提取数据库数据
entity.getCustomerInfo();
customerjTable1 = new javax.swing.JTable(entity.rowDataCustomer,titles);

}else if(i==1){ 
// 当i==0时,按钮没点击,执行searchCustomer(getSearchCustomerName());方法,get查询的text的值,并提取数据库数据
entity.searchCustomer(getSearchCustomerName());
customerjTable1=new javax.swing.JTable(entity.searchCustomerInfo,titles);
}




 public static Vector rowDataCustomer = new Vector();

    public static void getCustomerInfo() { //从数据看里取全部数据放到vector里,返回到jtable中
        String sql = "select * from customer";
        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(1));
                vcRows.add(rs.getString(2));