If Ω ⊂ Rn is a bounded domain, the existence of solutions u ∈ W01, p (Ω) of div u = f for f ∈ Lp (Ω) with vanishing mean value and 1 < p < ∞, is a basic result in the analysis of the Stokes equations. It is known that the result holds when Ω is a Lipschitz domain and that it is not valid for domains with external cusps. In this paper we prove that the result holds for John domains. Our proof is constructive: the solution u is given by an explicit integral operator acting on f. To prove that u ∈ W01, p (Ω) we make use of the Calderón-Zygmund singular integral operator theory and the Hardy-Littlewood maximal function. For domains satisfying the separation property introduced in [S. Buckley, P. Koskela, Sobolev-Poincaré implies John, Math. Res. Lett. 2 (5) (1995) 577-593], and 1 < p < n, we also prove a converse result, thus characterizing in this case the domains for which a continuous right inverse of the divergence exists. In particular, our result applies to simply connected planar domains because they satisfy the separation property.