подключение к удаленному MySQL серверу ошибок - PullRequest
0 голосов
/ 07 февраля 2012

Я пытаюсь подключиться к удаленному серверу (серверу моей школы для доступа к базе данных), но мне не повезло, я продолжаю получать это

SQL Exception:
State  : 08S01
Message: Communications link failure

Last packet sent to the server was 0 ms ago.
Error  : 0

Вот код, который я нашел в Java,просто скопировал, чтобы посмотреть, смогу ли я подключиться ..

public void test()
 {
    try
    {
       // Load the database driver
       Class.forName( "com.mysql.jdbc.Driver" ) ;

       // Get a connection to the database
       Connection conn = DriverManager.getConnection( "jdbc:mysql://my.db.url.edu;databaseName=marco;user=USERNAME;password=PASSWORD" ) ;

       // Print all warnings
       for( SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning() )
       {
          System.out.println( "SQL Warning:" ) ;
          System.out.println( "State  : " + warn.getSQLState()  ) ;
          System.out.println( "Message: " + warn.getMessage()   ) ;
          System.out.println( "Error  : " + warn.getErrorCode() ) ;
       }

       // Get a statement from the connection
       Statement stmt = conn.createStatement() ;

       // Execute the query
       ResultSet rs = stmt.executeQuery( "SELECT * FROM Test" ) ;

       // Loop through the result set
       while( rs.next() )
          System.out.println( rs.getString(1) ) ;

       // Close the result set, statement and the connection
       rs.close() ;
       stmt.close() ;
       conn.close() ;
   }
   catch( SQLException se )
   {
       System.out.println( "SQL Exception:" ) ;

       // Loop through the SQL Exceptions
       while( se != null )
       {
          System.out.println( "State  : " + se.getSQLState()  ) ;
          System.out.println( "Message: " + se.getMessage()   ) ;
          System.out.println( "Error  : " + se.getErrorCode() ) ;

          se = se.getNextException() ;
       }
   }
   catch( Exception e )
   {
      System.out.println( e ) ;
   }
 }
}

Просто чтобы дополнить информацию, я использую Vista.В чем может быть проблема?

С уважением

1 Ответ

1 голос
/ 07 февраля 2012

Существует множество возможных причин, по которым вы получаете «сбой соединения» при подключении к вашей базе данных.

  1. Брандмауэры и / или маршрутизаторы, блокирующие ваше соединение с БД
  2. Сама база данных не разрешает удаленное соединение

Если вы уверены, что случай 2 не применяется, вам придется проверить вещи на своей стороне, отключите антивирусное / брандмауэрное программное обеспечение на компьютере разработчика, если это не работает, обратитесь к администратору БД.

...