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"
甲建議表示讚賞。