I thought I'd add to what Sangsara & novanilla said above.
Cranberry & other vaccinium fruit species, such as blueberry, have condensed tannins that have been found to prevent the bacteria from adhering to the bladder walls & starting an infection, (it changes the thermodynamic properties of the bacteria in the urinary tract & creates an energy barrier that prevents them from making the structures necessary for them to latch onto the cells in the bladder wall & instigate an infection.) Interestingly, it does NOT affect the non-pathogenic microbes, leaving the natural flora undisturbed, which is one more reason it is preferred for use over antibiotics as a prophylactic measure, (once you have an infection, you need the antibiotics, cranberry won't stop an infection that's already started).
Unfortunately for us, the effect only lasts as long as the microbes are exposed to the juice, meaning, once the cranberry is no longer present, the bacteria will resume growth. So, to realize this antibacterial effect, one must consume cranberry juice, (or the capsules, tablets, etc), regularly, preferably daily! By the way, the results were the same when they tested sugar-free cranberry juice & cranberry juice cocktail.