Join the Stack Overflow Community
Stack Overflow is a community of 6.2 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up
    String name = "";
    String port = "3306";
    String user = "root";
    String pass = "";
    String dbname = "atm";
    String host="192.168.5.219"; // my local host ip address 
    // I want to do this only with IP address..
    try {

        Class.forName("com.mysql.jdbc.Driver").newInstance();
        String url = "jdbc:mysql://"+host+":"+  port + "/" + dbname;
        System.out.println("URL:" + url);
        //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection(url, user, pass);

        String qry2 = "select * from atm";
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery(qry2);
        while (rs.next()) {

            name = rs.getString("name");
            System.out.println("Name:" + name);
            j.setText(""+name);

        }
        rs.close();
        st.close();
        con.close();


    } catch (Exception e) {
        javax.swing.JOptionPane.showMessageDialog(null, e.getMessage());
        System.out.println(e.getMessage());
    }

When I run this I got an error:

error>> null, message from server: "Host 'DEEPAK-PC' is not allowed to connect to this MySQL server"

Actually I want to make a program that takes data from another PC connected to my LAN network in school. So that's why I want to do this with IP address.

share|improve this question
    
This is not a java problem. Is a MYSQL user permision related issue. Check this here – PbxMan Nov 28 '13 at 11:59

you have to first grant permission to access mysql from remote location

try this

GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.5.219'
    IDENTIFIED BY PASSWORD 'some_characters'  
    WITH GRANT OPTION;
FLUSH PRIVILEGES;

check this mysql site for more info

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.