We investigate nonergodic behaviors of the one-dimensional Bose-Hubbard model, which emerge in the unitary quantum dynamics starting with the initial state |ψ(0the presence of a trapping potential. We compute the level spacing statistic, the time evolution of the number imbalance between the odd and even sites, and the entanglement entropy in order to show that the system exhibits nonergodicity in a strongly interacting regime. Furthermore, the nonergodic behaviors appear even when the trapping potential is weak compared to the hopping energy. We derive the effective spin-1/2 XXZ Hamiltonian for the strongly interacting regimes by using a perturbation method. On the basis of the effective Hamiltonian, we show that the strength of the trapping potential is effectively enhanced by the onsite interaction, leading to the nonergodic behaviors. We also calculate the real-time dynamics under the effective Hamiltonian and find that the logarithmic growth of the entanglement entropy in time.