This is a wrapped exception and not really interesting. It is the root cause of the exception which actually tells us something about the root cause. Please look a bit further in the stacktrace. The chance is big that you'll then face a SQLException: Connection refused
or SQLException: Connection timed out
.
If this is true in your case as well, then all the possible causes are:
- IP address or hostname in JDBC URL is wrong.
- Hostname in JDBC URL is not recognized by local DNS server.
- Port number is missing or wrong in JDBC URL.
- DB server is down.
- DB server doesn't accept TCP/IP connections.
- Something in between Java and DB is blocking connections, e.g. a firewall or proxy.
To solve the one or the either, follow the following advices:
- Verify and test them with
ping
.
- Refresh DNS or use IP address in JDBC URL instead.
- Verify it based on
my.cnf
of MySQL DB.
- Start it.
- Verify if mysqld is started without the
--skip-networking
option.
- Disable firewall and/or configure firewall/proxy to allow/forward the port.
By the way (and unrelated to the actual problem), you don't necessarily need to load the JDBC driver on every getConnection()
call. Just only once during startup is enough.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…