0

I have a problem when I try to connect to a MySQL database. I am using MAMP on mac (local). My database name is "Hopital". Here is my function for the connection:

public Connexion(){
    try{ 
    Class.forName("com.mysql.jdbc.Driver");
    System.out.println("Driver ok");
    String url = "jdbc:mysql://localhost:8888/Hopital";
    String user = "root";
    String password = "root";
    Connection cn = DriverManager.getConnection(url, user, password);
    System.out.println("Connexion ok !");
    }catch(Exception e){
        e.printStackTrace():}

The thing is that I have no error but my output is only "Driver ok", the other print doesn't work so I guess that the connection is not working.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • You are using MySQL. PhpMyAdmin is only an web-based administration frontend for MySQL. You can't connect to PhpMyAdmin from Java. MySQL is normally not running on port 8888, but on 3306. – Mark Rotteveel Apr 16 '18 at 09:47
  • @MarkRotteveel Thank you for your answer ! So the url should be "jdbc:mysql://localhost:3606/Hopital" ? When I do that I have a huge error starting with : "Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.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. ". – Ipman97 Apr 16 '18 at 10:02
  • For that error, see https://stackoverflow.com/questions/6865538/solving-a-communications-link-failure-with-jdbc-and-mysql – Mark Rotteveel Apr 16 '18 at 10:04
  • @MarkRotteveel I checked all the possible solutions and it is still not working. I am working with someone on this project and on windows everything is perfectly working. Maybe it could be a problem of access rights or ports ? – Ipman97 Apr 16 '18 at 12:59

0 Answers0