2016-09-06 55 views
0

嗨我想從一個表使用SQL查詢帶來的結果,但我得到的消息SQLServerResultSet3作爲結果。Sqlserver在joptionpane中顯示結果與sql查詢

我以下面的代碼爲例,但它不適用於我,任何想法我做錯了,因爲我是新的這種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(); 

    } 
+0

什麼「不工作」? – StanislavL

+0

我沒有得到顯着的產品,低於20 ....我想要顯示的產品 –

+0

,所以我想要帶來的結果到joptionpane爲exable所有產品低於20 –

回答

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); } 
}