Sqlserver使用sql查询在joptionpane中显示结果

时间:2016-09-06 11:42:26

标签: java sql

您好我想使用SQL查询从表中提取结果,但结果显示消息SQLServerResultSet3

我以下面的代码为例,但它对我不起作用,不知道我做错了什么因为我是这个ty的新手!

searching from database and showing the output

private void searchquantity(){
  //ArrayList <Update_del_insert_products> proList =new ArrayList <Update_del_insert_products> ();
         Connection connection =getConnection();

         String query ="SELECT * FROM Products WHERE Pro_Quantity <=20";
         Statement sts=null;
         ResultSet rsr=null;
         try{
            sts = connection.createStatement();
            rsr = sts.executeQuery(query);
            //Update_del_insert_products  update_del_insert_products ;
              if(rsr.next()) {
              JOptionPane.showMessageDialog(null,rsr);

        }else{
            JOptionPane.showMessageDialog(null, "Not Found");
        }

    }catch (Exception e) { JOptionPane.showMessageDialog(null, e); }
}

=============================================== ==================

private void Check_CapacityActionPerformed(java.awt.event.ActionEvent evt) {                                               

         searchquantity();

    }  

1 个答案:

答案 0 :(得分:0)

检查数量表中<20以下的产品的行

private void searchquantity(){

         Connection connection =getConnection();

         String query ="SELECT * FROM Products WHERE Pro_Quantity <=20";
         Statement sts=null;
         ResultSet rsr=null;
         int a=0;
         try{
            sts = connection.createStatement();
            rsr = sts.executeQuery(query);

             while(rsr.next()) {
              JOptionPane.showMessageDialog(null,rsr.getString("Pro_Id"));
              JOptionPane.showMessageDialog(null,rsr.getString("Pro_Name"));
              a=1;
             }
              if (a==0){

            JOptionPane.showMessageDialog(null, "Not Found");
            a=0;}



    }catch (Exception e) { JOptionPane.showMessageDialog(null, e); }
}