Why a short sequence of modules is exact if and only if the short sequence of their localization at any prime ideal is exact? 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...
 A: 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.
A: A slightly closer-to-the-ground solution to this problem.
Proposition: Let $L \to N \to P$ be a sequence of $A$-modules, where $A$ is a commutative unital ring. Then the following two are equivalent:


*

*The sequence $L\to N\to P$ is exact

*For every maximal ideal $m$ of $A$, the sequence $L_m \to N_m \to P_m$ is exact.


Proof: That 1 implies 2 follows immediately from that, for any multiplicative set $S$, the mapping $M$ to $S^{-1}M$ of $A$-modules to $S^{-1}A$-modules is an exact functor.
So, we prove that 2 implies 1. Let $f: L\to N$ be the first arrow and $g: N\to P$ be the second arrow. 
Part one: $\mathrm{Im}(f)\subseteq \mathrm{ker}(g)$
Take an arbitrary $\ell\in L$ and let $\mathrm{Ann}(g(f(l))) = \{x\in A: xg(f(l)) = 0\}$. This is clearly an ideal, and it is the entire ring iff $g(f(l))=0$. So, suppose for contradiction that $\mathrm{Ann}(g(f(l)))\neq 0$, so there exists some maximal ideal $m\supset\mathrm{Ann}(g(f(l)))$. By hypothesis, we now have that the sequence
$$L_m \to N_m\to P_m$$
is exact. So $g_m(f_m(\frac{l}{1}))=\frac{0}{1}$ in $P_m$, giving $\frac{g(f(l))}{1}=\frac{0}{1}$ in $P_m$.
That is, there exists some $u\in A\setminus m$ such that $u g(f(l))=0$. But this is a contradiction, since any such $u$ lies in $\mathrm{Ann}(g(f(l)))$ and thus in $m$, not in its complement.
Part two: $\mathrm{ker}(g) \subset \mathrm{im}(f)$
Let $n\in \mathrm{ker}(g)$, and let $I= \{x\in A: xn \in \mathrm{im}(f)\}$, which can easily be verified to be an ideal (since $\mathrm{im}(f)$ is a submodule). Now obviously $I=A$ iff $n\in \mathrm{im}(f)$. So suppose for contradiction that $I\neq A$, so that there exists a maximal ideal $m$ in $A$ containing $I$.
Again, we have by hypothesis that the sequence
$$L_m \to N_m\to P_m$$
is exact. Thus, since $\frac{n}{1}\in\mathrm{ker}(g_m)$, there exists an $\frac{l}{s}\in L_m$ such that $f_m(\frac{l}{s})=\frac{n}{1}$ in $N_m$. This equality gives us that there exists a $u\in A\setminus m$ such that
$$u(f(l)-ns) = 0 \Leftrightarrow f(ul) = usn$$
so that $usn\in \mathrm{Im}(f)$. Now, by definition of $I$, this implies $us\in I$. But $us \in A\setminus m$ too, which gives our contradiction. ∎
