In this paper, we consider a spectrum sharing scheme that is a joint optimization of relay selection and power allocation at the secondary transmitter, which aims to achieve the maximum possible throughput for the secondary user. This paper considers the scenario where the primary user is incapable of supporting its target signal-to-noise ratio (SNR). More especially, the secondary transmitter tries to assist the primary user with achieving its target SNR by cooperative amplify-and-forward (AF) relaying with two-phase. By exhaustive search for all candidate secondary transmitters, an optimal secondary transmitter can be selected, which not only can satisfy the primary user's target SNR, but also maximize the secondary user's throughput. The optimal secondary transmitter acts as a relay for the primary user by allocating a part of its power to amplify-and-forward the primary signal over the primary user's licensed spectrum bands. At the same time, as a reward, the optimal secondary transmitter uses the remaining power to transmit its own signal over the remaining licensed spectrum bands. Thus, the secondary user obtains the spectrum access opportunities. Besides, there is no interference between the primary user and the secondary user. We study the joint optimization of relay selection and power allocation such that the secondary user's throughput is maximized on the condition that it satisfies the primary user's target SNR. From the simulation, it is shown that the joint optimization of relay selection and power allocation provides a significant throughput gain compared with random relay selection with optimal power allocation (OPA) and random relay selection with water-filling power allocation (WPA). Moreover, the simulation results also shown that our spectrum sharing scheme obtains the win-win solution for the primary system and the secondary system.