I have a table that contains two columns CODE where there is all the bar code and VARIABLE initialized to 0 at the beginning . I have to update the table when I scan the bar code , I have to add 1 to variable , when I scan it twice VARIABLE =2.... I have tried to do it like but it does not work .Can anyone help?
 String query = "INSERT INTO TABLE (CODE,VARIABLE) VALUES(?,?) ON DUPLICATE KEY UPDATE VARIABLE='"+VARIABLE+1+"'";
                try {
                    if (connect != null) {
                           PreparedStatement statement = connect.prepareStatement(query);
                         statement.setString(1, "%" + res + "%");
                        statement.setInt(2,VARIABLE );
                        r=statement.executeQuery();
                        if (r.next()) {
                            message = "Updated";
                            String code = r.getString("CODE");
                            int var = r.getInt("VARIABLE");
                            INFOSOMME.setText(message);
                            INFOSOMME.setText(code);
                            INFOSOMME.setText(var);
                        } else {
                            message = "Error";
                            INFOSOMME.setText(message);
                        }
                    } else {
                        message = "Error in connection with SQL server";
                        INFOSOMME.setText(message);
                    }
                } catch (SQLException e) {
                    etat = false;
                    message = "Got an exception!";
                    System.err.println(e.getMessage());
                }
            }
        });
ERROR: 08-03 09:43:44.966 30393-30393/com.example.practicas.myapplication W/System.err: Sintaxis incorrecta cerca de la palabra clave 'ON'.
I have tried to change the query to String query="INSERT INTO TABLE(CODE,VARIABLE) VALUES(?,0);" + "Update TABLE SET VARIABLE=VARIABLE+1 WHERE CODE LIKE ?"; and I got this error /System.err: The executeQuery method must return a result set.
 
     
     
    