A measurement of inclusive, prompt, and non-prompt J/ψ production in p-Pb collisions at a nucleon-nucleon centre-of-mass energy sNN = 5.02 TeV is presented. The inclusive J/ψ mesons are reconstructed in the dielectron decay channel at midrapidity down to a transverse momentum pT = 0. The inclusive J/ψ nuclear modification factor RpPb is calculated by comparing the new results in p-Pb collisions to a recently measured proton-proton reference at the same centre-of-mass energy. Non-prompt J/ψ mesons, which originate from the decay of beauty hadrons, are separated from promptly produced J/ψ on a statistical basis for pT larger than 1.0 GeV/c. These results are based on the data sample collected by the ALICE detector during the 2016 LHC p-Pb run, corresponding to an integrated luminosity Lint = 292 ± 11 μb−1, which is six times larger than the previous publications. The total uncertainty on the pT-integrated inclusive J/ψ and non-prompt J/ψ cross section are reduced by a factor 1.7 and 2.2, respectively. The measured cross sections and RpPb are compared with theoretical models that include various combinations of cold nuclear matter effects. From the non-prompt J/ψ production cross section, the b b ¯ production cross section at midrapidity, d σbb ¯/dy, and the total cross section extrapolated over full phase space, σbb ¯, are derived. [Figure not available: see fulltext.]