简体   繁体   中英

Could not create connection to database server - java mysql connector

I can't connect to a mysql database on my "live-server" but it works just fine on my local computer.

In my main class I am doing this:

try {
    main.connection.open();
} catch (SQLException e1) {
    log.fatal(e1.getMessage());
    System.exit(0); 
}

And the open method looks like this

public void open() throws SQLException{
    if(con != null) close();
    con = DriverManager.getConnection(url, user, password);
}

After a couple of minutes running I am getting this:

14:35:47.434 [main] FATAL se.mypack.Server - Could not create connection to database server. Attempted reconnect 3 times. Giving up.

How do I debug this? The url, server and password variables is correct. What might be the problem here?

Using mysql-connector-java-5.1.29-bin.jar

First you have to make sure you have loaded your DB-driver class. It goes as the following: Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

This is for DERBY DB. There is a different driver class for each DB, but the idea is the same.

If you already did it, check if you have a tcp connection to the DB server from the client machine that tries to establish the connection. You can use : ping -t your.server.ip. If you get a response, try to establish telet connection to that url + port number (the port that the DB listener listens to, for Oracle it will be 1521, for Derby it is 1527..) and see that you don't get any connection refuse messages. If your connection attempt failed, see if the DB listener is up, or whether you have a fire wall issue.

Good Luck, Yosi Lev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM