TITLE: Spectrum of $\mathcal{O}(U)$
QUESTION [5 upvotes]: Let $X=\operatorname{Spec}(A)$ be the spectrum of the comm. ring $A$ and let $\mathcal{O}$ be the associated sheaf of rings, i.e. for $U \subseteq X$ open, $\mathcal{O}(U)$ is the ring of all functions $s: U \to \prod_{p \in U}A_p$ such that for all $p \in U$ there is an open neigbourhood $V \subseteq U$ of $p$ and there are $a \in A, f \in A \setminus \bigcup_{q \in V}q$ with $s(q) = a/f$ for all $q \in V$. 
Question: What is $\operatorname{Spec}\mathcal{O}(U)$ ? 
There are two special cases for $U$ that are easy to handle: 
(1) We have $\mathcal{O}(X)=A$ and thus $\operatorname{Spec}\mathcal{O}(U)(X)=X$. 
(2) For a principal open subset $D(f),\, \,\mathcal{O}(D(f))=A_f$ and thus $\operatorname{Spec}\mathcal{O}(D(f))=D(f)$. 
Therefore I suppose $\operatorname{Spec}\mathcal{O}(U)=U$. I found the map $$U \to \operatorname{Spec}\mathcal{O}(U),\, q \mapsto \mathcal{O}(U) \cap \prod_{p \in U} B_p$$ where $B_p: =A_p$ for $p \neq q$ and $B_q := qA_q$. But I'm not able to show that it is surjective. 
Any hint or reference is appreciated. Please note that the question is no homework, but an attempt to get a better understanding of the ring $\mathcal{O}(U)$.

REPLY [4 votes]: Just to add to Georges' answer, this map 
$$
j: Y \to \operatorname{Spec}\mathcal{O}(Y)
$$
is universal with respect to maps to affine space. That is, for any morphism $\varphi: Y \to \operatorname{Spec}A$, there is a unique morphism $\tilde{\varphi}: \operatorname{Spec}\mathcal{O}(Y) \to \operatorname{Spec}A$ such that the $\varphi = \tilde{\varphi}\circ j$. This follows from the natural isomorphism $\operatorname{Hom}_{Sch}(X, \operatorname{Spec}A) = \operatorname{Hom}_{CommRing}(A, \mathcal{O}(X))$. So in some sense $\operatorname{Spec}\mathcal{O}(Y)$ is the closest affine scheme to $Y$.