Yeah, exercise maintains your body, but if you're still eating a caloric positive diet, you'll gain mass. Thats just how it works.
Fixing your diet, eating less, and even intermittent fasting are the key to sustainable weight loss. Exercise is a good part of the mental discipline to create a structure around you to get healthy, but it all comes down to calories. You can (technically) sit on the couch all day and still lose significant weight.
Only minus for people when they're quite obese is that a mix of better diet and fasting can have really dramatic results right away that taper off. People can lose 10-20 pounds in a month, in a healthy way, but then that same habit the next month might be back to 1 to 5 pounds of weight loss, which is why people get discouraged. The bloating and fluid retention from poor diet choices are the first things to drop, and they go fast.