Unable to insert and retrieve mysql server database information

I created a database called test (table name demo) on wamp on my friend pc.i, I can see this table from my browser using my friend's ip address. but I want to insert and retrieve data into this database (test) using java code from my computer. I try this, but netbeans shows an error message.

here is my code :


package ashdemo;

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

public class Ashdemo {

        public static void main(String args[]) throws InstantiationException, IllegalAccessException
    {
        try{
            Class.forName("com.mysql.jdbc.Driver").newInstance();
                 Connection con = DriverManager.getConnection("jdbc:mysql://friend's_ipaddress:3306/test","username","password



"); 
                    Statement stmt=con.createStatement();
                  stmt.executeUpdate("Insert into demo values(1,'abc','nagpur')");
                    //ResultSet rs= stmt.executeQuery("Select name from demo where id=1");
                    //rs.next();
                   //String name= rs.getString("name");               
                    //System.out.println(name);
                    System.out.println("DOne..");
                   //INSERT INTO `student`(`id`, `name`, `address`) VALUES (1,'amol','nagpur');
                con.close();

              }
    catch(ClassNotFoundException | SQLException e){
        System.out.println("error"+e);
    }

    }

    }
error message is : 

errorjava.sql.SQLException: access denied for user 'username' @ 'myipaddress' (using password: YES)

+1
source share
1 answer

You need to configure mysql to allow remote connection for a specific user . The default syntax is:

grant <permission> on <database> to <user>@<location> identified by <password>

, -

grant all on test.* to 'username'@'your_ipaddress' identified by 'password'

MySQL.

IP - test.

  • IP- , -

grant all on *.* to '%'@'%' identified by 'password'

, , -

FLUSH PRIVILEGES;

.

+2

All Articles