title: Java to MySQL: How to update row with a value from variable?
body: <p>I have a table <code>TotalSales</code> on my database with columns Date(Primary) and Sales. I send query thru my Java Program. </p>
  
  <p>I want to add a row if Date row not exists, and if Date row exists, the value on Sales will be updated. On update, the new value on Sales will be 'current value on Sales' + 'the value of variable totalBill'.</p>
  
  <p>Lets say before execution: row under Sales = 0,
           after execution: row under Sales = Sales + totalBill;</p>
  
  <p>I tried this code:</p>
  
  <pre><code>String query = "INSERT INTO TotalSales (Date, Sales) VALUES(date, totalBill)
                  ON DUPLICATE KEY UPDATE Sales= VALUES(Sales)+VALUES(totalBill)";
  st = con.prepareStatement(query);
  st.execute();
  </code></pre>
  
  <p>But doesn't work: </p>
  
  <pre><code>com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'totalBill' in 'field list'
  </code></pre>
  
  <p>Can anyone help?</p>