I have a mac running mysql on localhost:3306. I am trying to connect to it via a Spring Beans App (Java) but am getting errors. Can anyone please assist? I am doing:
String jdbc_url = "jdbc:mysql://" + hostname + "/" + database;
try (Connection conn = DriverManager.getConnection(jdbc_url, db_username, db_password)) {
... my code here ...
}
I have tried String jdbc_url = "jdbc:mysql://docker-mysql:3306/mydb" but I got:
ocessing failed; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.] with root cause
java.net.ConnectException: Connection timed out
I have also tried: "mysql+mysqlconnector://root:mypassword@host.docker.internal:3306/mydb"; but I got the error:
java.sql.SQLException: No suitable driver found for mysql+mysqlconnector://root:mypassword@host.docker.internal:3306/mydb
I also tried:
jdbc:mysql://localhost:3306/mydb
but this failed as well because (I think) localhost is the localhost of the docker container and NOT my local machine.