Your second attempt is almost correct (you're missing a minus sign on the final answer...and its csc x, not cot x).
There are two ways to go about this:
1) Make the substitution $\displaystyle u=\sin x$. Then $\displaystyle \displaystyle\int\dfrac{\cos x}{\sin^2x}\,dx\xrightarrow{u=\sin x}{}\int\dfrac{\,du}{u^2}=\ldots$
2) Observe that $\displaystyle \dfrac{\cos x}{\sin^2 x}=\dfrac{1}{\sin x}\cdot\dfrac{\cos x}{\sin x}=\csc x\cot x$ and recall that $\displaystyle \dfrac{\,d}{\,dx}\left[\csc x\right]=-\csc x\cot x$.
So either way you do this, you should end up with $\displaystyle \displaystyle\int\dfrac{\cos x}{\sin^2x}\,dx=-\csc x+C$.
I would have done this slightly differently.
It has been proven that for any function f(x), $\displaystyle \displaystyle \int f'(x)f(x)^n dx=\frac{1}{n+1}[f(x)^{n+1}]+c$
This applies here if you write this as:
$\displaystyle [Cos(x)][Sin(x)^{-2}]$
as f(x) = sin x; n = -2; f'(x) = Cos(x)
Substituting into:
$\displaystyle \frac{1}{n+1}[f(x)^{n+1}]+c$
Gives $\displaystyle \frac{1}{-2+1}[Sin(x)^{-2+1}]+c$
$\displaystyle =\frac{1}{-1}[Sin(x)^{-1}]+c$
$\displaystyle =\displaystyle\frac{-1}{Sin(x)}$
$\displaystyle =-\csc(x) + c$
I don't know how you can all remember integrals like $\displaystyle \displaystyle \int{\csc{x}\cot{x}\,dx}$ or $\displaystyle \displaystyle \int{f'(x)[f(x)]^n\,dx} = \frac{1}{n+1}[f(x)]^{n+1} + C$ off the top of your head. I prefer to remember the procedures, and in this case, to reduce everything to sines and cosines and use substitution - at least then I only have to remember a couple of fundamental integrals
You should be able to remember"
Of course, if m is odd, you can do the same thing, switching "sine" and "cosine".If, in the integral $\displaystyle \int sin^n(x)cos^m(x)dx$, n is odd, say n= 2k+ 1, you can factor out one "sine" to use with the differential: $\displaystyle \int sin^{2k}(x) cos^m(x) (sin(x)dx)$, then use $\displaystyle sin^2(x)= 1- cos^2(x)$ to get
$\displaystyle \int (1- cos^2(x))^k cos^m(x)(sin(x)dx)$
and now the substitution u= cos(x), so that du= -sin(x)dx, makes that a polynomial integtration:
$\displaystyle -\int (1- u^2)^k u^m u$
This also works if either m or n (or both) are negative but gives a "rational function" integtral rather than a polynomial integral.
The specific formulas others gave may be quicker for specific values of m or n, but that is, in my opinion, the simplest general method.
(If both m and n are even, you can use $\displaystyle sin^2(x)= (1/2)(1- cos(2x)$ and/or $\displaystyle cos^2(x)= (1/2)(1+ cos(2x))$ to reduce the powers.)