Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何允许从外部访问phpMyAdmin的数据库?_Java_Mysql_Phpmyadmin - Fatal编程技术网

Java 如何允许从外部访问phpMyAdmin的数据库?

Java 如何允许从外部访问phpMyAdmin的数据库?,java,mysql,phpmyadmin,Java,Mysql,Phpmyadmin,我已允许在第一台电脑上访问phpMyAdmin。我可以在浏览器中打开phpMyAdminhttp://192.168.100.10:8080/phpmyadmin在本地局域网的另一台电脑上。而且我还可以在另一台PC上的phpMyAdmin中通过浏览器DB打开 但我无法通过java代码创建到DB的连接: Class.forName("com.mysql.jdbc.Driver"); // Setup the connection with the DB Properties info = new

我已允许在第一台电脑上访问phpMyAdmin。我可以在浏览器中打开phpMyAdmin
http://192.168.100.10:8080/phpmyadmin
在本地局域网的另一台电脑上。而且我还可以在另一台PC上的phpMyAdmin中通过浏览器DB打开

但我无法通过java代码创建到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();
在这里我发现我需要“允许网络访问MySQL”
如何在phpMyAdmin中做到这一点?

尝试使用这种方式检查您的端口号我认为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;
        }
    }
}

Class.forName
没有在您的代码中执行任何操作。您的
DriverManager
会为您处理这些。您是对的,非常感谢。你节省了我的薪水)你是welcom@NickUnuchek
jdbc:mysql://ip_of_host_server:3306/Database_name
应该是一个字符串,而不是像您现在所做的那样
“jdbc:mysql://ip_of_host_server:3306/Database_name“
是,谢谢@YCF_L的更正。
Class.forName(driver);
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://ip_of_host_server:3306/Database_name", DB_username, DB_password);