4 Replies Latest reply: Feb 8, 2008 11:01 AM by 796254 RSS

    how to connect db in local network

    807603
      hello

      I write intranet program in my network ar 2 pc

      pc1 []= client
      pc2 [IP: 10.0.0.1] = server
      on pc3 [IP: 10.0.0.2] is mysql database

      I try to connect database from server using folowing parameter
      private String driverName = "com.mysql.jdbc.Driver";
      private String Url = "jdbc:mysql://10.0.0.2/myXXdb";
      private  String DBPwd ="mypassword";
      public  String DBUser="root";
      
      Exception:
      
      com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 
      
      ** BEGIN NESTED EXCEPTION ** 
      
      java.net.SocketException
      MESSAGE: java.net.ConnectException: Connection timed out: connect
      
      BUT wenn I connect datbase on pc2   using 
      
      private String driverName = "com.mysql.jdbc.Driver";
      private String Url = "jdbc:mysql://localhost/myXXdb";
      private  String DBPwd ="mypassword";
      public  String DBUser="root";
      
      works fine 
      
      how to connect database on pc3 ?????
      Thanks
        • 1. Re: how to connect db in local network
          807603
          anybody in this world to help me ???
          • 2. Re: how to connect db in local network
            807603
            Your post is bit unclear, you said there are two hosts then described three.
            You said you unable to connect from server but able to connect from pc2 but also you said server is pc2.
            Please clear situation...

            P.S.: Anyway you have problem with communication not with MySQL itself.
            • 3. Re: how to connect db in local network
              807603
              Let me see if I got what you mean. You are trying to connect to your database from the localhost(works fine) and from another computer in the same network(error).

              Well, and all I that you are changing in your code is String Url?

              When you connect from the localhost, all you need it is to create a Connection object.

              But to connect from another machine, you need a Client/Server code. That�s why it�s not working. You need to create a Socket object.

              I hope it helps...
              • 4. Re: how to connect db in local network
                796254
                ThomYork wrote:
                Let me see if I got what you mean. You are trying to connect to your database from the localhost(works fine) and from another computer in the same network(error).

                Well, and all I that you are changing in your code is String Url?

                When you connect from the localhost, all you need it is to create a Connection object.

                But to connect from another machine, you need a Client/Server code. That�s why it�s not working. You need to create a Socket object.
                Um, no. Wrong. The JDBC driver makes that connection for you.

                I think the reason it works "fine" on your local PC and not on the networked database has to do with MySQL permissions. You have to GRANT permission to connect from your PC in the MySQL instance running on the server. I believe the user permission table includes host, username, and password info. Talk to the DBA that owns the instance about adding your app to the users table.

                %

                PS - Thom, LOVE you in Radiohead.