Java - Netbeans IDE
I have this code but the variable Priceperitem is not found, can anyone explain? or show me an easier way of selecting a record from a table in a database and setting its value as a variable?
Price P/Item is the name of column within the database table.
String sql = "SELECT Price P/Item FROM tblResources";
try {
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
while (rs.next()){
double Priceperitem = rs.getDouble("Price P/Item");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Runtime Error");
}
and then :
try {
Total = Quantity * Priceperitem; (This is where Priceperitem is not found.)
btnCalculateTotal.setText("Total: £"+Total+"0");
}catch (Exception e){
System.out.println("Error Calculating Total");
}