dumazy
dumazy

Reputation: 14435

can't connect to mysql database in servlet

I keep getting this error when i'm trying to connect to my MySQL database:

exception

javax.servlet.ServletException: JDBC Problem: 
root cause

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.
root cause

java.net.ConnectException: Connection timed out: connect

here's some code:

Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        try{
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection
                    ("jdbc:mysql://mysql11.000webhost.com/database_name","user_name","password");
        stmt = con.createStatement();
        rs = stmt.executeQuery("INSERT into emailadresses('email') values ('"+email+"')");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(EmailServlet.class.getName()).log(Level.SEVERE, null, ex);
        }catch(SQLException e){
            throw new ServletException("JDBC Problem: ", e);
        }

edit: I have the mysql-connector-java jar file in my libraries

EDIT: FOUND THE PROBLEM I was looking for the answer on the site where I host my database and found this:

JDBC/ODBC is not supported here

that s*cks...

Upvotes: 0

Views: 2947

Answers (4)

Eriky R. Kashivagui
Eriky R. Kashivagui

Reputation: 482

"Signals that an error occurred while attempting to connect a socket to a remote address and port. Typically, the connection was refused remotely (e.g., no process is listening on the remote address/port)". - From Oracle Docs

Take a look into your connection string, be sure that the database, username and the password are correctly typed.

Another cause may be that your database server is not up.

Upvotes: 1

Sumit Desai
Sumit Desai

Reputation: 1760

Try connecting that database from any database client(like sqlyog) from machine you are running your application. If connection fails from client also, then surely it's a network issue.

Upvotes: 1

Luca Putzu
Luca Putzu

Reputation: 1456

Definitely a networking problem. Note that your tcp connection is NOT refused, instead it incurs in a timeout error. In my experience that behaviour could be caused by a TCP handshaking not correctly finalized (eg. a firewall dropping SYN packets).

Upvotes: 1

Gimby
Gimby

Reputation: 5274

Yes its not a classpath problem, its a networking problem. For some reason no network connection can be established to the given host from your client machine. So yeah, could be lots of things.

  • server is actually not running!
  • host/IP wrong
  • firewall (your side)
  • firewall (other side)
  • whatever else networking problem there might be

Upvotes: 1

Related Questions