We apply the Gröbner basis to the ansatz method in quantum mechanics to obtain the energy eigenvalues and the wave functions in a very simple manner. There are important physical potentials such as the Cornell interaction which play significant roles in particle physics and can be treated via this technique. As a typical example, the algorithm is applied to the semi-relativistic spinless Salpeter equation under the Cornell interaction. Many other applications of the idea in a wide range of physical fields are listed as well.