Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2010
    Location
    India
    Posts
    4
    Rep Power
    0

    Default Unable to connect to remote mysql database using IP Address

    Dear friends,

    I am Kranthi. I am new to java programming. I am having the following problem. Can any one of you help me..??

    I am using Xamplite 1.7.2
    My Xampp is running on IP: 192.168.1.16 and port: 3306 in our office network.

    I have written one java program in order to connect to the IP: 192.168.1.15:3306

    I am have written my program like this:

    public class DataSource {
    private static Connection con;

    public static Connection getConnection(){
    try{
    Class.forName("com.mysql.jdbc.Driver").newInstance ();
    con = DriverManager.getConnection("jdbc:mysql://192.168.1.15:3306/school","root","");
    }catch(Exception e){
    System.out.println("Exception: "+e);
    }
    return con;
    }
    }

    Output:

    At the end it is returning null instead of connection object. Why it is happening. On the remote system i am having username: root and password is not specified. And, my connection program is like this....!!

    Can any of you tell me... why it is happening..!!

    Please help mee..!!

    Kranthi
    Last edited by kranthipoturaju; 04-28-2010 at 11:31 AM.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Well, I won't comment on the "security" (or lack of it of that system), but have you granted that user rights to connect from the host from which it is attempting to connect? See the MySQL manual, the user management section, especially the part about the GRANT statement.

    Also, it would definately help to know what exception you're getting (as an exception is the reason that method is returning null, of course).

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    808
    Rep Power
    6

    Default

    just for trial sake u just try without username and password.let us see..
    Ramya:cool:

  4. #4
    Join Date
    Feb 2010
    Location
    India
    Posts
    4
    Rep Power
    0

    Default I tried with out username and password

    Dear friend,

    I have tried to connect without providing username and password, i.e with one parameter.

    And, i have modified user privileges in phpmyadmin now it is connecting if i provide my system ip instead of localhost.

    But, again i am unable to connect from the different system.

    my modified code is like this:

    public class DataSource {
    private static Connection con;

    public static Connection getConnection(){
    try{
    Class.forName("com.mysql.jdbc.Driver").newInstance ();
    con = DriverManager.getConnection("jdbc:mysql://192.168.1.15:3306/school","root",""); // But i can not connect to ip: 192.168.1.16
    }catch(Exception e){
    System.out.println("Exception!!"+e);
    }
    return con;
    }
    }

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    And what do your grants look like, and, again, what exception are you getting?

Similar Threads

  1. Java program to ping remote machine using IP address..?
    By prabhurangan in forum New To Java
    Replies: 19
    Last Post: 11-22-2011, 03:58 PM
  2. failed to connect to remote vm
    By plummer in forum Eclipse
    Replies: 1
    Last Post: 05-08-2009, 08:11 AM
  3. Replies: 15
    Last Post: 04-15-2009, 01:51 AM
  4. Replies: 0
    Last Post: 10-31-2008, 07:07 PM
  5. Replies: 2
    Last Post: 06-12-2008, 07:09 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •