Spectroscopy is a powerful tool for studying molecules and is commonly performed on large thermal molecular ensembles that are perturbed by motional shifts and interactions with the environment and one another, resulting in convoluted spectra and limited resolution. Here, we use generally applicable quantum-logic techniques to prepare a trapped molecular ion in a single quantum state, drive terahertz rotational transitions with an optical frequency comb, and read out the final state non-destructively, leaving the molecule ready for further manipulation. We resolve rotational transitions to 11 significant digits and derive the rotational constant of CaH+ to be B_R = 142501777.9(1.7) kHz. Our approach suits a wide range of molecular ions, including polyatomics and species relevant for tests of fundamental physics, chemistry, and astrophysics.