I want to connect to PostgreSQL database in java, which is on Amazon EC2. I can connect to it using a postgres client on Mac called Postico. I specify next info:
Nickname
Host (ec2-xx-xx-xx-xx.xx-xx-x.compute.amazonaws.com)
User
Password
Database name
SSH host
User
Password - blank
Private key - .pem file
I could not find any example about how to connect it in Java. I found some RedshiftJDBC driver and added it to project. than I tried this:
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your MySQL JDBC Driver?");
e.printStackTrace();
return;
}
System.out.println("MySQL JDBC Driver Registered!");
try {
this.connection = DriverManager.getConnection("jdbc:postgresql://" +DNS+"/"+myDBname, MYSQLUSER, MYSQLPW);
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
}
if (connection != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
I knew it would not work, but at least I tried)) I have no idea how to specify Private key in request (how to send it), or whatever. Could someone help me ? Thank you.