I am trying to retieve the total salaries from a table where the customer name is X. I have the code below however there seems to be an error.
public void total(String name){
double totals=0;
Properties conProps = new Properties();
conProps.setProperty("user", "user");
conProps.setProperty("password", "pass");
try {
con = DriverManager.getConnection("jdbc:mysql://91.208.99.2:3379/link", conProps);
con.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
} catch (SQLException ex) {
Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex);
}
String query=("SELECT SUM(salary) FROM orders WHERE cus_name = ?");
try {
con.setAutoCommit(false);
st = (com.mysql.jdbc.PreparedStatement) con.prepareStatement(query);
st.setString(1, name);
ResultSet salaries=st.executeQuery();
while (salaries.next())
totals+=salaries.getDouble("salary");
}catch ( SQLException e) {
e.printStackTrace();
}
System.out.println("Sum of column = " + totals);
}
I am getting Error:
java.sql.SQLException: Column 'salary' not found. I can confirm that the column salary is in the table..