Evaluating an improper integral using the Residue Theorem

As pointed out in the comments, the residue you found was incorrect:

$$\operatorname{Res}(f(z),3i) = \lim_{z\to3i}(z-3i)f(z) = \lim_{z\to3i}\frac{z^2}{(z^2+1)(z+3i)} = \frac{-9}{(-9+1)(3i+3i)} = \frac9{48i} = -\frac{3i}{16}$$

But what your solution is really missing is an indication of the contour you're using, and showing that the contribution of the integral over the part of the contour not containing the real line is zero. (Maybe you've already done this but omitted the details from your post, but I'll just add the details here for posterity as well as personal practice.)

Presumably, you take $\gamma$ to be the upper half of a circle with its diameter on the real interval $[-R,R]$. Then

$$\oint_\gamma f(z) \, dz = \int_{\gamma_R} f(z) \, dz + \int_{-R}^R f(z) \, dz$$

where $\gamma_R$ refers to the arc $|z|=R \land \operatorname{Im}(z)\ge0$.

As $R\to\infty$, we recover the integral you want to compute from the second integral above. Meanwhile, the first integral is bounded by

$$\begin{align} \left|\int_{\gamma_R}f(z) \, dz\right| &= \left|\int_0^\pi f\left(Re^{it}\right) \, iRe^{it} \, dt\right| \\[1ex] &\le \frac{\pi R^3}{\left|R^2e^{2it}+1\right|\left|R^2e^{2it}+9\right|} \end{align}$$

and this vanishes as $R$ gets arbitrarily large.


Also, using Calculus $$ \frac{x^2}{(x^2+1)(x^2+9)}=\frac{1}{8}\left(\frac{9}{x^2+9}-\frac{1}{x^2+1}\right) $$ and $$ \int_{-\infty}^\infty\frac{dx}{x^2+1}=\tan^{-1}(x)\Big|_{x=-\infty}^{x=\infty}=\pi, \qquad \int_{-\infty}^\infty\frac{dx}{x^2+9}=\frac{1}{3}\tan^{-1}(x/3)\Big|_{x=-\infty}^{x=\infty}=\frac{\pi}{3}, $$ and hence $$ \int_{-\infty}^\infty\frac{x^2}{(x^2+1)(x^2+9)}=\frac{\pi}{4}. $$