gpt4 book ai didi

java - 使用 Netbeans 连接到远程 mySQL(cPanel,phpMyAdmin)

转载 作者:行者123 更新时间:2023-11-29 00:21:23 24 4
gpt4 key购买 nike

我已经在远程主机上使用 cPanel 和 phpMyAdmin 为我的网站创建了 MySQL 数据库,现在我想用我的简单 Java 程序连接到这个数据库。我试试这个代码:

 import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Main {

public static void main(String[] args) {
try{
Connection con=DriverManager.getConnection("jdbc:mysql://sfg.ge/sfgge_mysql", "my_username", "my_password");

Statement state=(Statement) con.createStatement();
String name="shota";
int id=3;
String insert = "INSERT INTO student VALUES ("+ id +",'"+ name +"')";
state.executeUpdate(insert);
}
catch(Exception ex){

}
}
}

在这段代码中

       DriverManager.getConnection(String url, username, pass) 

SQLException 抛出这样的错误:

    null,  message from server: 
"Host '188.129.228.176' is not allowed to connect to this MySQL server"

任何建议表示赞赏。

最佳答案

添加新帐户:

'user1'@'exact_host' - host is specified

CREATE USER 'user1'@'exact_host'

'user1'@'%' - for any host.

CREATE USER 'user1'@'%'

授予您需要的权限并连接新帐户。也看看这个:

Make sure that the server has not been configured to ignore network connections or (if you are attempting to connect remotely) that it has not been configured to listen only locally on its network interfaces. If the server was started with --skip-networking, it will not accept TCP/IP connections at all. If the server was started with --bind-address=127.0.0.1, it will listen for TCP/IP connections only locally on the loopback interface and will not accept remote connections

关于java - 使用 Netbeans 连接到远程 mySQL(cPanel,phpMyAdmin),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20937349/

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