Stationary solutions on a bounded interval for an initial-boundary value problem to Korteweg–de Vries and modified Korteweg–de Vries equation (for the last one both in focusing and defocusing cases) are constructed. The method of the study is based on the theory of conservative systems with one degree of freedom. The obtained solutions turn out to be periodic. Exact relations between the length of the interval and coefficients of the equations which are necessary and sufficient for the existence of nontrivial solutions are established. © Springer International Publishing Switzerland 2016.