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.
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. 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);???? try to check this
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.