Use PreparedStatement . Thus, you assign a placeholder, and the JDBC driver will do this correctly by sending instructions to the database, as well as parameters as arguments.
String updateStatement = "update " + dbName + ".COFFEES " + "set TOTAL = TOTAL + ? " + "where COF_NAME = ?"; PreparedStatement updateTotal = con.prepareStatement(updateStatement); updateTotal.setInt(1, e.getValue().intValue()); updateTotal.setString(2, e.getKey());
The question marks in the above representation are placeholders.
Since these values ββare passed as parameters, you have no problem citing, and it also protects you from SQL injection .
source share