The following problem is a part of the exercise 10 of Chapter III of S. Lang's Algebra, which turns out to be a little difficult:
Let $A$ be a unital commutative ring and $M$, $M'$, $M''$ be $A$-modules. Then $$0\to M'\to M\to M''\to 0$$ is exact if and only if $$0\to M'_\mathfrak{p}\to M_\mathfrak{p}\to M''_\mathfrak{p}\to 0$$ is exact for each prime ideal $\mathfrak p\subset A$, where $M_\mathfrak{p}=S^{-1}M$ (here $S=A\setminus\mathfrak p$) is the localization at $\mathfrak p$.
The "only if" part is a direct corollary of a previous exercise (exercise 9 of Chapter III, precisely) of this book and the "if" part is what really makes me stuck. I tried reduction to absurdity, but had not idea how to choose a proper prime ideal $\mathfrak p$ to get a contradiction. So I would like to ask how to carry on the proof the necessity of this problem...
Thanks in advance...
Lemma: If $M_P=0$ for all maximal ideals, then $M=0$.
assume that $0 \neq m \in M$ exists so its annihilator, $\mathrm{ann} (m)$, is contained in some maximal ideal $P$ since $\mathrm{ann}(m) \neq (1)$. If we localize at this maximal ideal, $m/1$ will be zero by hypothesis. By the definition of localization, this implies that there exists $u \in R \setminus\mathrm{ann}(m)$ so that $u(m-0)= 0 \implies um = 0$, which means that $u \in \mathrm{ann}(m)$, a contradiction.
Consider a sequence of modules $$ M^{\prime} \to M \to M^{\prime \prime}.$$
We claim that if $$ M^{\prime}_P \to M_P \to M^{\prime \prime}_P$$ is exact for every maximal ideal $P$ of $R$, then the first sequence is exact as well.
Let $f$ be the first arrow, and $g$ the second, with their localizations $f_P$ and $g_P$.
The first inclusion $\mathrm{Im} f \subseteq \ker g$ is immediate since $0=S^{-1}g \circ S^{-1}f=S^{-1}(g \circ f)$ for localization at any $S$, so $g \circ f$ is trivial by the lemma.
This means that $\ker g /\mathrm{im} f$ is well defined, and is $0$ at the localization, since $(\ker g/ \mathrm{Im}f)_P \cong (\ker g)_P/(\mathrm{Im}f)_P=\ker g_P / \mathrm{Im} f_P=0$ since localization commutes with quotients, and the hypothesis of local exactness. But then, again by the lemma, we obtain equality $\ker g=\mathrm{Im}(f)$.
some of this is a bit sloppy, let me know if I can clarify anywhere. I have also shamelessly plagiarized one of my blog posts here.