1
votes

I am trying to use JDBC to connect to a mysql database on our school's server. Here is my code:

    try
    {
      // Step 1: Load the JDBC driver. 
        Class.forName("com.mysql.jdbc.Driver");

        System.out.println(1);


      // Step 2: Establish the connection to the database. 
        String url = "jdbc:mysql://csci.lakeforest.edu:3306/csci427_spring11";

        System.out.println(2);

        Connection conn = DriverManager.getConnection(url,"username","password");  

        System.out.println(3);

        Statement stmt = conn.createStatement (); // Create statement

        System.out.println(2);
    }
    catch (Exception e)
    {
      System.err.println("Got an exception! "); 
      System.err.println(e.getMessage()); 
    } 

The 1 and 2 are printing, but then I get this error:

**Got an exception! 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.**

Any help will be appreciated.

Thank you

1
I had this very same problem and it was the driver I was using. See about updating/finding a new jar file for your MySql driver. I can't remember exactly what I did to solve this, but I believe it has everything to do with drivers and server configuration, not your code. - Zoidberg
Hi, Thanks for the response. I downloaded the jar file from the mysql website just a few days ago, so I think it is up to date. Any other suggestions? - meanie

1 Answers

2
votes

That usually means:

  1. The server is down
  2. The name of the server is wrong
  3. The port number is wrong