2017-01-25 24 views
2

私は最初のPCでphpMyAdminにアクセスできました。ローカルLANの別のPCのブラウザhttp://192.168.100.10:8080/phpmyadminでphpMyAdminを開くことができます。私は、「ネットワークアクセスを許可する必要があることがわかった外部からphpMyAdminのDBへのアクセスを許可する方法は?

Class.forName("com.mysql.jdbc.Driver"); 
// Setup the connection with the DB 
Properties info = new Properties(); 
info.put("characterEncoding", "UTF-8"); 
info.put("user", "root"); 
info.put("password", ""); 
info.put("autoReconnect", "true"); 
info.put("useSSL", "false"); 
info.put("failOverReadOnly", "false"); 
info.put("maxReconnects", "10"); 
info.put("connectTimeout", "2000"); 

DriverManager.setLoginTimeout(10); 
mConnection = DriverManager.getConnection(
    "jdbc:mysql://192.168.100.10:8080/flats_flx", info 
);//here it's stuck 

mStatement = mConnection.createStatement(); 
ここ

https://stackoverflow.com/a/27700425/2425851:そしてまた、私は別のPC

上のphpMyAdminにブラウザDBを経由して開くことができますしかし、私は、Javaコードを経由してDBへの接続を作成することはできませんMySQLへ」 phpMyAdminでこれを行う方法は?

+0

'Class.forName'は、あなたのコード内で何もしていません。あなたの 'DriverManager'がそれを処理します。 – 4castle

答えて

2

はあなたのポート番号を確認し、この方法を使用してみてください私は、MySQLが3306だと思う:

public class CreateConnection { 
    String driver = "com.mysql.jdbc.Driver"; 
    String DB_username = "username"; 
    String DB_password = "password"; 
    String DB_URL = "jdbc:mysql://192.168.100.10:3306/flats_flx"; 

    public Connection getConnection() { 
     try { 
      Class.forName(driver); 
      java.sql.Connection con = DriverManager.getConnection(DB_URL, DB_username, DB_password); 
      System.out.println(con); 
      return con; 

     } catch (ClassNotFoundException | SQLException e) { 
      System.out.println("Exception " + e); 
      return null; 
     } 
    } 
} 
+0

あなたは正しいです、多くの感謝です。あなたは私の給料を保存しました)) – NickUnuchek

+0

あなたはウェルカムです@NickUnuchek –

2
Class.forName(driver); 
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://ip_of_host_server:3306/Database_name", DB_username, DB_password); 
+0

'jdbc:mysql:// ip_of_host_server:3306/Database_name'は文字列でなければなりません。 " –

+0

はい! 、ありがとう@YCF_L訂正のために。 –

+0

あなたは歓迎です:) –

関連する問題