A converse of Whitehead's first and second lemma has been recently studied by P. Zusmanovich, e.g., see here. One of the results is as follows:
Theorem 0.2 (A converse to the Second Whitehead Lemma). A finite-dimensional Lie algebra over a field of characteristic zero such that its second cohomology with coefficients in any finite-dimensional module vanishes, is one of the following:
(i) an one-dimensional algebra;
(ii) a semisimple algebra;
(iii) the direct sum of a semisimple algebra and an one-dimensional algebra.
If you only require that $H^2$ vanishes for the trivial representation, we have much less, of course. By Dixmier's result, such a Lie algebra cannot be nilpotent. It might be solvable, however, e.g., a solvable, non-nilpotentent strongly rigid Lie algebra. More details are in Zusmanovich's paper.