2014-01-05 5 views
1

Я создал базу данных MySQL для своего сайта, используя cPanel и phpMyAdmin на удаленном хосте, и теперь я хочу подключиться к этой базе данных своей простой java-программой. Я пробую этот код:Подключиться к удаленному mySQL (cPanel, phpMyAdmin) с помощью Netbeans

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" 

A ny предложения оценили.

ответ

1

Добавить новую учетную запись:

'user1'@'exact_host' - host is specified 

CREATE USER 'user1'@'exact_host' 

или

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

CREATE USER 'user1'@'%' 

привилегии Grant вам нужно, и связаться с новой учетной записью. Также смотрите:

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 
Смежные вопросы