You seem a bit confused about how to use Dirac notation, so I'll derive the result from scratch. For any operator $O$, the definition of the expectation value is
$$\langle O \rangle = \langle \psi | O | \psi \rangle.$$
In order to write this as an integral, just note that
$$1 = \int dx \, | x \rangle \langle x |.$$
By putting in two "factors of $1$", we get
$$\langle O \rangle = \int dx \, dx ' \, \langle \psi | x \rangle \langle x | O | x' \rangle \langle x' | \psi \rangle.$$
The definition of the wavefunction is
$$\psi(x) = \langle x | \psi \rangle.$$
In particular, it doesn't make sense to write $|\psi(x) \rangle$ in Dirac notation, since $\psi(x)$ is just a number, not a ket. Anyway, using the definition of the wavefunction, we have
$$\langle O \rangle = \int dx \, dx ' \, \psi^*(x) \langle x | O | x' \rangle \psi(x').$$
This is how you calculate the expectation value of any operator in the position basis. In your case,
$$\langle x | p^2 | x ' \rangle = \left( \frac{\hbar}{i} \right)^2 \delta''(x - x')$$
essentially by the definition of $p$, so
$$\langle p^2 \rangle = - \hbar^2 \int dx \, dx' \, \psi^*(x) \delta''(x - x') \psi(x').$$
Now integrate by parts with respect to $x'$ twice, to get
$$\langle p^2 \rangle = - \hbar^2 \int dx \, dx' \, \psi^*(x) \delta(x - x') \psi''(x') = - \hbar^2 \int dx \, \psi^*(x) \psi''(x).$$
That's your answer.
tl;dr: Neither of your expressions are right. Instead, differentiate $\psi(x)$ twice.