I wanted to ask how to retrieve the actual values of the private and public keys from the KeyPair object because i need to export them and save in a database.
Have you looked into the docs?
Try the following :
getModulus
getPublicExponent
getPrivateExponent
They all return BigInteger
than can in turn be stored.
Also see if the raw encoded format is of help.