I'm trying to give access to client computer from my server and also tryin to revoke the granted access... the grant is successful but the revoking is not working please help.
hms is the satabase that i want to give access to my clients..
my code

 try {

            Connection con = getDBConnection();
            Statement stmt = con.createStatement();
            if (sts == true) {
                String query = "GRANT INSERT,SELECT,UPDATE,DELETE ON hms.* TO '" + MainFrame.dbUser + "'@'" + ip + "' IDENTIFIED BY '" + MainFrame.dbPassword + "'";
                stmt.execute(query);
                System.out.println(query);
                JOptionPane.showMessageDialog(null, "Permission granted to '" + ip + "' !");
            }
            else{
                String query ="REVOKE INSERT,SELECT,UPDATE,DELETE on hms.* FROM '"+MainFrame.dbUser+"'@'"+ip+"' identified by '"+MainFrame.dbPassword+"';";
                stmt.execute(query);
                System.out.println(query);
                JOptionPane.showMessageDialog(null, "Permission denied for '" + ip + "' !");
            }


        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(null, "Failed");
        }

this is the error i get

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'howday'@'192.168.1.69' to database 'hms'

please help!!!

Recommended Answers

All 3 Replies

If you compare the syntax of the GRANT and REVOKE statements, GRANT requires user_specification and REVOKE only requires a user. The difference is that user_sepcification requires user plus the IDENTIFIED BY, while user is just that, a user. Try changing the REVOKE query to:

String query ="REVOKE INSERT,SELECT,UPDATE,DELETE on hms.* FROM '"+MainFrame.dbUser+"'@'"+ip+"';";

i want to give access to my clients using java.when i tried the code it is showing "com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'root'@'183.83.51.134' to database 'printer_system_master'

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author hesperus
 */

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.sql.*;
import javax.swing.JOptionPane;

public class Provide_db_privillages {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
            try {
                URL connection1 = new URL("http://checkip.amazonaws.com/");
                URLConnection con = connection1.openConnection();
                String ip = null;                
                BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
                ip = reader.readLine();
                Class.forName("com.mysql.jdbc.Driver");
                Connection connection = DriverManager.getConnection("jdbc:mysql://52.74.143.118:3306/printer_system_master", "root", "root");
//                Connection con = getDBConnection();
                Statement stmt = connection.createStatement();
                String query = "GRANT INSERT,SELECT,UPDATE,DELETE ON printer_system_master.* TO 'printer_system_master.root'@'" + ip + "' IDENTIFIED BY 'printer_system_master.root'";
                stmt.execute(query);
                System.out.println(query);
                JOptionPane.showMessageDialog(null, "Permission granted to '" + ip + "' !");

            } catch (Exception ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(null, "Failed");
            }
    }    
}

Kishore_5 : this is an unrelated matter to an old thread.
Please don't hijack threads, but start your own.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.