integral of a square root function by substitution. A practice problem:

$$\int \sqrt{x^2+9}\ dx $$

So what I did was to substitute $x$ with $\tan \theta$, which yields

$$\int \sqrt{9\tan^2\theta+9}\ dx $$

Then I brought the 9 out

$$\int 3\sqrt{\tan^2\theta+1}\ dx $$

Using trig identity I simplified it to:

$$\int 3\sqrt{\sec^2\theta}\ dx $$

which is 

$$\int 3{\sec θ}\ dx $$

Now as you can see, it still has an ending of $dx$, but $d\theta= [\arctan(x/3)]$, which is really messy and long and complicated. I know what it is but its is just too messy to be typed here, (it has a fraction of a fraction and I don't really know how to write it here) and it makes the question even harder. But I remember professor teaching me to substitute $x$ with $a\tan\theta$ , where $9$ is $a^2$
I have been working on this for almost an hour and I don't know how to continue from here. Please help me.

The solution to your problem is that we have $x = \tan\theta$. The differential of this would be $dx = \sec^2\theta\,d\theta$. You replace this with $dx$. You do this because you want your entire integral in terms of $\theta$. You don't need to solve for $\theta$ and get $d\theta$. Doing this causes $x$'s to appear in the integrand when we're actually trying to get rid of them.
