You are right that you can do sanitation yourself and, thus, be safe from injections. But this is more error prone and therefore less secure. In other words, doing it yourself introduces more chances for errors that can lead to vulnerabilities in relation to injections.
, . , SQL ('foo'), ; MySQL ("foo"), , , MySQL.
PreparedStatement, JDBC Driver, . , , JDBC , , -, , . , , , .
, preparedStatement.setString(1, name), ( , - JDBC ) :
public void setString(int idx, String value) {
String sanitized = ourPrivateSanitizeMethod(value);
internalSetString(idx, value);
}
( , , JDBC -, .)
, , myUserInputVar . :
private void updateUser(int name, String id) throws SQLException {
myStat.executeUpdate("UPDATE user SET name=" + name + " WHERE id=" + id);
}
? , , , name . " ", (, hello ' world hello '' world). , UPDATE user SET name=? WHERE id=? , PreparedStatement , ?.