简体   繁体   中英

Getting error in executeUpdate Java MySQL

I trying to set "ALL PRIVILEGES" from Java on remote MySQL database test and user test . Here is snippet of my code:

Class.forName("com.mysql.jdbc.Driver");
Connection con = null;
con = (Connection) DriverManager.getConnection("jdbc:mysql://xx.xxx.xxx.xx:3306/?user=root&password=pswrd");

Statement st = con.createStatement();
int res = st.executeUpdate("GRANT ALL PRIVILEGES ON test.* TO 'test'@'%' IDENTIFIED BY '12345';");

Nothing extraordinary. All queries from root user work fine, but in this partucular case I'm getting error:

Exception in thread "main"   com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'root'@'%' to database 'test'

What did I do wrong?

UPDATE

Here's answer . So, the problem wasn't solved ...

尝试建立与

DriverManager.getConnection("jdbc:mysql://hostname:port/dbname","username", "password");

请确保由“ pswrd”标识的“ root @ yourHost”(尤其是来自yourHost)具有管理此数据库特权的权限。

尝试添加主机,例如“ test” @“ yourhost

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM