简体   繁体   English

从MySql数据库获取UnitPrice的值时出错

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

I am developing a Medical Store Management System In Java using MySQL database,there is a little issue in calculating the total bill,it's not fetching the UnitPrice from the Database.Please help me if you know. 我正在使用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);

Why do you put your query as a parameter of the getDouble() - function. 为什么将查询作为getDouble()函数的参数。 It has to take the column name as far as I know. 据我所知,它必须采用列名。

Also, just don't start your variable-names with upper case letters. 另外,只是不要用大写字母开头变量名。

Double Bill = result * rs.getDouble(sql);???? Double Bill = result * rs.getDouble(sql); ???? try to check this 尝试检查一下

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM