I want to create a new user for a MySQL database from NetBeans but I don't know the core code for it.
I've tried:
try {
String query = "CREATE USER = '?' @'localhost' IDENTIFIED BY = '?'; ";
con = DriverManager.getConnection(url, uname, pwd);
PreparedStatement pstmnt = con.prepareStatement(query);
pstmnt.setString(1, newUser[0]);
pstmnt.setString(2, newUser[3]);
pstmnt.execute();
pstmnt.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
The output is:
java.sql.SQLException:
Parameter index out of range (1 > number of parameters, which is 0).
I know in MySQL you can create a new user using:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';