2017-10-30 13 views
0

Azureに掲載されたWebアプリケーションを使用して外部MySQLデータベースに接続しようとしています。コードは、Tomcatは、ローカルホスト上でホストされている上で完全に正常に動作しているが、アズールの全機能がエラーとの接続のリターンを必要とする:Azure - 外部MySQLデータベースに接続しようとすると拒否されました

Exception: java.net.SocketException: Permission denied: connect Message: ; nested exception is: java.net.SocketException: Permission denied: connect  

接続機能コードは次のとおりです。

private static String hostName = "sql11.freesqldatabase.com"; 
private static String dbName = "xxxx"; 
private static String user = "xxxx"; 
private static String password = "xxxx"; 
private static String portNumber = "xxxx"; 
private Connection connect() { 
    String url ="jdbc:mysql://"+hostName+":"+portNumber+"/"+dbName+"?user="+user+"&password="+password; 
    Connection conn = null; 
     try { 
      Class.forName("com.mysql.jdbc.Driver"); 
     } catch (ClassNotFoundException e1) { 
      e1.printStackTrace(); 
     } 
     try { 
      conn = DriverManager.getConnection(url); 
     } catch (SQLException e) { 
      System.out.println(e.getMessage()); 
      e.printStackTrace(); 
     } 
    return conn; 
} 
+0

MySQL用Azureデータベースを使用していますか? –

+0

私はAzureデータベースとFreesqldatabaseの両方を試していました - 両方とも、localhostのTomcatサーバー上で実行されている間に完全にうまく動作しますが、Azureサーバーに投稿されたときにエラーが表示されます – obirek999

答えて

0

私は疲れたあなたの問題を再現するのではなく、失敗しました。

ここでは、Azure MySQL Databaseで接続をテストするJava spring-bootプロジェクトを作成しようとしました。

私のコードのスニペット:

private static String hostName = "<your host name>"; 
    private static String dbName = "sys"; 
    private static String user = "<user name>"; 
    private static String password = "password"; 
    private static String portNumber = "3306"; 

    @RequestMapping("/hello") 
    public String index() throws SQLException { 
     Connection conn = null; 
     try { 
      Class.forName("com.mysql.cj.jdbc.Driver"); 
     } catch (ClassNotFoundException e1) { 
      e1.printStackTrace(); 
     } 
     try { 
      String url = "jdbc:mysql://"+hostName+":"+portNumber+"/"+dbName+"?verifyServerCertificate=true&useSSL=true&requireSSL=false&serverTimezone=UTC"; 
      conn = DriverManager.getConnection(url, user, password); 

     } catch (SQLException e) { 
      System.out.println("error!!!!"); 
      System.out.println(e.getMessage()); 
      e.printStackTrace(); 
      return e.getMessage(); 
     } 
     return conn.getCatalog(); 
    } 

私のweb.configファイル:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
    <handlers> 
     <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" /> 
    </handlers> 
    <httpPlatform processPath="%JAVA_HOME%\bin\java.exe" 
     arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar &quot;%HOME%\site\wwwroot\demo-0.0.1-SNAPSHOT.jar&quot;"> 
    </httpPlatform> 
    </system.webServer> 
</configuration> 

あなたに接続できない場合は、以下のようにポイントをチェックすることができますデータベース:

1.設定されたSSLパラメータが間違っています。

2.灰色のWebアプリケーションの白いIP addressを設定してください。

enter image description here

3.Don'tミスあなたweb.config-Djava.net.preferIPv4Stack=true設定。

あなたはこのスレッドから詳細を見つけることができる:JavaMail API to iMail -- java.net.SocketException: Permission denied: connect

は、それはあなたのお役に立てば幸いです。

+0

Azureプラットフォームで公開されたアプリケーションで、 Azure MySQLデータベースへの接続ではありません。 – obirek999

+0

@ obirek999あなたの投稿によると、あなたのWebアプリケーションは完全にdbに接続しているようですが、紺色のプラットフォームでは動作していないようです。だから、私はあなたのWebアプリケーションの設定を確認することをお勧めします。 –

関連する問題