1
我已经在我的网站上使用cPanel和phpMyAdmin在远程主机上创建了MySQL数据库,现在我想连接到这个数据库我简单的java程序。我试试这个代码:使用Netbeans连接到远程mySQL(cPanel,phpMyAdmin)
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"
甲建议表示赞赏。