netbeans,界面组合框的点击刷新应用和从数据库提取数据添加到列表应用

来源:互联网 发布:广州星知电子有限公司 编辑:程序博客网 时间:2024/06/08 07:26
 jComboBox1.removeAllItems();
        new DBConnect();
        String sql5 = "select * from blog";
        ResultSet rs5 = DBConnect.executeQuery(sql5);
         try {
             int nCol = rs5.getMetaData().getColumnCount();
        rs5.last();
        int nRow = rs5.getRow();
        rs5.absolute(0);
//        rs1.next();
//        int row = rs1.getInt("a");
        jComboBox1.setMaximumRowCount(nRow);
       
            //String sql2 = "select problem from QAlist";
            //ResultSet rs2 = DBConnect.executeQuery(sql2);
            while (rs5.next()) {
                jComboBox1.addItem(rs5.getString("title"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(Answer.class.getName()).log(Level.SEVERE, null, ex);
        }

    }  



 public Search(String str1) {
        initComponents();
        this.setLocationRelativeTo(null);
        //int i = 0, j = 0;
        System.out.print(str1);
        int row;
        try {
            new DBConnect();
            String sql1 = "select * from QAlist  where problem LIKE '%" + str1 + "%'";
            //rs = DBConnect.executeQuery("select COUNT(*) as a from Course_table");
            ResultSet rs1 = DBConnect.executeQuery(sql1);
            int nCol = rs1.getMetaData().getColumnCount();
            rs1.last();
            int nRow = rs1.getRow();
            rs1.absolute(0);
                      for (int i = 0; rs1.next(); i++) {
                for (int j = 0; j < nCol; j++) {
                    jTable1.setValueAt(rs1.getString(j + 1), i, j);
                  
                }
            }
           
            DBConnect.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
       
    }                                      

0 0