I have instances of amazon ec2 and rds which both run in a virtual private cloud. The rds contains a mysql database. I am able to connect to the rds database with mysql workbench by inputting the database information(host, port#, database, user) and also the ssh details for the ec2 instance(host, port#, user, keyfile).
I am now writing a java program that needs to access the database. I am confused as to how this can be done with the JDBC(java database connection) library. There are examples online regarding the use of JDBC, however they don't seem to be addressing certain issues I am facing.
For example, to connect to my database I must also ssh into the ec2 instance. Secondly my ec2 instance uses a key file rather than a password and I have not seen any examples of how to implement this in code.
I would really appreciate any advice or code example pertaining to this issue. Please let me know if I need to clarify anything. Thanks