-1

I can't connect to the local database even if the connection parameters are correct, using jdbc. If I try to connect by terminal or by some client i can connect.

But if I try to connect to remote database it works

this is the error:

Connected to the target VM, address: '127.0.0.1:49986', transport: 'socket'
Exception in thread "main" 2019-04-15 12:16:55 FATAL AbstractConnectorDB - Unable to connect to database jdbc:mysql://localhost:3306/my_db?autoReconnect=true&useSSL=false
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
com.mycompany.database.relational.exceptions.ConnectionFailedException:     Fatal error: Unable to connect to db jdbc:mysql://localhost:3306/my_db?autoReconnect=true&useSSL=false @root
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    ...
    ... 17 more
Disconnected from the target VM, address: '127.0.0.1:49986', transport: 'socket'



What could be the problem?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Vito Lipari
  • 795
  • 8
  • 35
  • Possible duplicate of [MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up](https://stackoverflow.com/questions/36827222/mysqlnontransientconnectionexception-could-not-create-connection-to-database-se) – AxelH Apr 15 '19 at 10:32
  • Are you sure about your credentials, the URI used. Can you provide the code that tried to open the connection ? – AxelH Apr 15 '19 at 10:32
  • jdbc:mysql://localhost:3306/my_db?autoReconnect=true&useSSL=false – Vito Lipari Apr 15 '19 at 10:40
  • Please don't add things like "SOLVED" to your question title. Either accept an answer that helped you or post your own solution as an answer and accept that after the timeout. – Mark Rotteveel Apr 15 '19 at 17:04

2 Answers2

1

Yes, your connection properties are correct on your PC but not on the VM. Use your PC's IP Address instead.

Grim
  • 1,938
  • 10
  • 56
  • 123
  • even with the address (127.0.0.1) I have the same error – Vito Lipari Apr 15 '19 at 10:57
  • What do you mean "even"? If you try 127.0.0.1 and then 127.0.0.1 you have changed nothing! It is clear that you got the same error! I repeat: Use your PC's IP Address please. – Grim Apr 15 '19 at 11:13
  • ok, i'm sorry for my english! I tried with 127.0.0.1, 192.168.33.75, 0.0.0.0 and i always get the same error! – Vito Lipari Apr 15 '19 at 12:04
  • Ah ok, i guess the `.75` is your target. Unfortunately I have - under this radical changed limitation - not yet an idea whats wrong. – Grim May 03 '19 at 22:14
0

The source of the problem was: I was using MySQL version 5 in my POM, but I had MySQL 8 on my computer.
So I completely deleted MySQL from my computer and installed the version I needed

Vito Lipari
  • 795
  • 8
  • 35