Due to the broadcast nature of wireless networks, jamming attacks are inevitable. Therefore, this paper considers enhancing the throughput of a primary user (PU) suffering from a random jamming attack near the receiver in a cognitive radio network. A cooperative spectrum-sharing scheme is proposed between the PU and an energy-constrained secondary user (SU) harvesting non-RF energy. The SU location is optimized to maximize the PU throughput. Then, a decision problem is formulated to adaptively optimize the PU decision regarding the cooperation with SU and maximize the PU throughput in the long run, considering the uncertainties about the jammer activity and the SU’s available energy. Unlike the previous work, our scheme assumes no prior knowledge about the parameters controlling the jammer’s random behavior, the energy harvesting process, and the sensing system. Bayesian reinforcement learning (BRL) is adopted to learn the unknown parameters and optimize the PU decisions simultaneously. The Bayes-adaptive mixed-observable Markov decision process (BAMOMDP) model is proposed to extend the current BRL models to handle the state’s mixed observability. Simulation results show the efficiency and robustness of the proposed scheme in enhancing the PU/SU throughputs and its ability to adapt to non-stationary environments. Compared with previous work, the proposed scheme can improve the PU average throughput by 15% in non-stationary environments and up to 40% in stationary environments with low jamming sensing capabilities.