Question:
I am finding hard time connecting to RDS using JDBC connection, I am able to connect through MYSQL workbench, I deployed my WAR file in A WSwhich is running tomcat, this WAR file has my JDBCcode connecting to RDS, but I am not even able to establish connection.
My code is as below:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public static Connection getconnection(){ String connectionUrl = "jdbc:mysql://testinstance.cj3ixhryi3fb.us-west-2.rds.amazonaws.com:3306/testDB"; String dbUser = "testuser"; String dbPwd = "usertest"; Connection conn = null; try { conn = (Connection) DriverManager.getConnection(connectionUrl, dbUser, dbPwd); System.out.println("conn Available"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("fetch otion error"+e.getLocalizedMessage()); } return conn; } |
I included all the necessary jar files, and rules security groups but no luck.
I am using the EC2 security group for RDS. Does RDS will use ec2 security groups?
or I need to have different security group for RDS?
the testinstance is a working link if any one wanna test.
Answer:
It could be that your instance is in a VPC and your RDS instance isn’t set up in a VPC subnet group.
If you want to connect to an RDS instance from a server instance in a VPC, your RDS instance has to be deployed in a VPC subnet.
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.CreateDBSubnetGroup.html