java - unable to insert and retrive mysql server database information -


i have created database named test(table name demo) on wamp on friend's pc.i able see table browser using ip address of friend's pc. want insert , retrive data database(test) using java code pc. try netbeans shows error message.

here 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 demo values(1,'abc','nagpur')");                     //resultset rs= stmt.executequery("select name demo id=1");                     //rs.next();                    //string name= rs.getstring("name");                                    //system.out.println(name);                     system.out.println("done..");                    //insert `student`(`id`, `name`, `address`) values (1,'amol','nagpur');                 con.close();                }     catch(classnotfoundexception | sqlexception e){         system.out.println("error"+e);     }      }      } error message :  

errorjava.sql.sqlexception: access denied user 'username'@'myipaddress' (using password: yes)

you need set mysql allow remote connection particular user. default syntax is:

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

so here have use-

grant on test.* 'username'@'your_ipaddress' identified 'password'

run command in mysql command prompt.

this allow username connect ip using password , give permissions on tables in database-test.

  • to allow any user connect from ip address , use all tables in database use following syntax-

grant on *.* '%'@'%' identified 'password'

and have use following command-

flush privileges;

to reload privileges.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -