Nika Tsogiaidze
Nika Tsogiaidze

Reputation: 1107

Connect to remote mySQL(cPanel,phpMyAdmin) using Netbeans

I have created MySQL database for my website using cPanel and phpMyAdmin on remote host and now i want to connect to this database my simple java program.I try this code:

 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){

   }
 }
}

In this code

       DriverManager.getConnection(String url, username, pass) 

SQLException throws such error:

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

Any suggestions appreciated.

Upvotes: 1

Views: 4888

Answers (1)

iPot
iPot

Reputation: 23

Add new account:

'user1'@'exact_host' - host is specified

CREATE USER 'user1'@'exact_host'

or

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

CREATE USER 'user1'@'%'

Grant privileges you need and connect with new account. Also look at this:

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

Upvotes: 1

Related Questions