簡體   English   中英

從MySql數據庫獲取UnitPrice的值時出錯

[英]Error in fetching value of UnitPrice from MySql Database

我正在使用MySQL數據庫在Java中開發醫療商店管理系統,因此在計算總賬單時存在一個小問題,它不是從數據庫中獲取單價。如果您知道的話,請幫助我。

     Connection con = Database.DBConnect();
     String sql = "select UnitPrice from medicines where MedicineName= ?";
     try{
         st = con.prepareStatement(sql);
         st.setString(1,(ProductName.getSelectedItem().toString()));
         rs = st.executeQuery();
         while(rs.next()){
             int result = Integer.parseInt(EnterQuantity.getText());
             Double   Bill = result * rs.getDouble(sql);
             JOptionPane.showMessageDialog(null,"The total Bill = " +Bill);
         }

      } catch (SQLException e) {
          JOptionPane.showMessageDialog(null,e);
    }
Double   Bill = result * rs.getDouble(sql);

為什么將查詢作為getDouble()函數的參數。 據我所知,它必須采用列名。

另外,只是不要用大寫字母開頭變量名。

Double Bill = result * rs.getDouble(sql); ???? 嘗試檢查一下

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM