In MySQL command line client after logging in as root, I typed:
connect mydb;
grant all privileges on mydb.* to 'admin'@'localhost' identified by 'pass';
Now within Java,
I succesfully connect to the db using the admin userid using drivers.
Statement put=connect.createStatement();
//**WORKS succesfully**
put.execute("insert into mydb.emp values(100,joe)");
//**does NOT work**
put.execute("grant all privileges on mydb.* to 'john'@'localhost' identified by 'pass'");
Why does an insert command work but grant command never work through Java?
Please help.
解决方案put.execute(MySQL query)
in here you can execute only MySQL query but
grant all privileges on mydb.* to 'admin'@'localhost' identified by 'pass';
Not a MySQL query it is just a command for MySQL.