'SQL executeUpdate() seems to commit data, but that is not the case. How can I find my error?

I curently work on few SQL queries (MSSQL 2O14), but only "SELECT" query works with executeQuery(). I had use execute() and executeUpdate() on "INSERT INTO" and "UPDATE" queries, but whereas it looks like working, no way.

FYI, in "UPDATE_PREVIOUS_H_LOT_STATUT, int count= p.executeUpdate(); return 1. If h_lot_number is an unknown lot number, count = 0. So, if I use wrong data in input, my query isn't executed(Until here, I agree) but when I use the expected data, the query is executed but there is no change in my DB. How can I find where my error is ?

UPDATE Function :

public static boolean UPDATE_PREVIOUS_H_LOT_STATUT(String h_lot_number_old) {
        try {
            setUpConnexion("mainDB");
            String baseQuery = "UPDATE valve_assembly_h SET statut = 'Expiré' WHERE h_lot_number = '" + h_lot_number_old + "'";
             //PreparedStatement p = newTransact("UPDATE valve_assembly_h SET statut = 'Expiré' WHERE h_lot_number = '" + h_lot_number_old + "'", "mainDB");
            PreparedStatement toReturn = (PreparedStatement) mainCon.prepareStatement(baseQuery);
            int count = toReturn.executeUpdate();
            if (count > 0) {
                Log.d("Sucess : ", "Previous h_lot updated.");
                closeCons();
                return true;
            } else {
                Log.e("Error : ", "No lot found with this number.");
                closeCons();
                return false;
            }
        } catch (SQLException e) {
            error = e.getMessage();
            Log.e("Error :", error);
            closeCons();
            return false;
        }

    }

LOAD PREVIOUS NUMBER FUNCTION (works perfectly)

public static String LOAD_PREVIOUS_H_LOT_NUMBER(String machineNumber) {
        String s = "";
        try {
            setUpConnexion("mainDB");
            ResultSet RS = executeQuery("SELECT h_lot_number FROM valve_assembly_h WHERE machine_number = '" + machineNumber + "' AND statut = 'Actif'", "mainDB");
            while (RS.next()) {
                s = RS.getString(1);
                Log.d("Success : ", "Lot number : " + s);
            }
            closeResultSet(RS);
        } catch (Exception e) {
            error = e.getMessage();
            Log.e("Error :", error);
            s = error;
        }
        closeCons();
        return s;
    }

Set up connection function : (works perfectly)

public static boolean setUpConnexion(String DBNAME) {
        StrictMode.ThreadPolicy policy;
        policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        String connectURL;
        try {
    CONNECTION MS SQL SERVER
}
            return true;
        } catch (Exception e) {
            System.out.println("SQL ERROR: " + e.getMessage());
            e.printStackTrace();
            return false;
        }
    }


Solution 1:[1]

Try to commit the transaction manually through the Connection object ,hope it helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 karim farhouti