gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:36:28 28 4
gpt4 key购买 nike

我已允许在第一台 PC 上访问 phpMyAdmin。我可以通过在本地 LAN 中的另一台 PC 上的浏览​​器 http://192.168.100.10:8080/phpmyadmin 打开 phpMyAdmin。而且我还可以在另一台 PC 上的 phpMyAdmin 中通过浏览器数据库打开

但我无法通过 java 代码创建到数据库的连接:

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我发现我需要“允许网络访问 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;
}
}
}

关于java - 如何允许从外部访问 phpMyAdmin 的数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41860125/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com