您的位置:首页 > 编程语言 > Java开发

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

2015-09-30 17:22 531 查看
 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();

        }

       

    }                                      
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: