Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7166015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:20:41+00:00 2026-05-28T14:20:41+00:00

I am working on a interface in java swing.we have four system connected with

  • 0

I am working on a interface in java swing.we have four system connected with a lan.the interface is for accessing the database from the other system in the same local area network i used the following code to access the database by giving the ip address,database name,tablename but i could not connect the other systems database.how can i do this?

 public void dbconnection() {

        String name = "";
        String port = "3306";
        String user = "systech";
        String pass = "systech";
        String dbname = "cascade_demo";
        String host="192.168.1.61";

        try {

            Class.forName("com.mysql.jdbc.Driver");

              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 item_master";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(qry2);
            while (rs.next()) {

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

            }


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


        } catch (Exception e) {
            System.out.println("Exception:" + e);
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:20:42+00:00Added an answer on May 28, 2026 at 2:20 pm

    Use below code

    public void dbconnection() {
    
        String name = "";
        String port = "3306";
        String user = "systech";
        String pass = "systech";
        String dbname = "cascade_demo";
        String host="192.168.1.61";
    
        try {
            String url = "jdbc:mysql://"+host+":"+  port + "/" + dbname;
            Class.forName("com.mysql.jdbc.Driver").newInstance ();
            Connection con = DriverManager.getConnection(url, user, pass);
            String qry2 = "select * from item_master";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(qry2);
            while (rs.next()) {
                System.out.println("Name:" + rs.getString(1));
            }
    
            rs.close();
            st.close();
            con.close();
    
    
        } catch (Exception e) {
            System.out.println("Exception:" + e);
        }
    }
    

    Also, make sure to include jar file for connecting. You will get jar file here.

    Update 1:

    So, you have a

    CommunicationsException: Communications link failure
    

    I’m quoting from this answer which also contains a step-by-step MySQL+JDBC tutorial:

    If you get a SQLException: Connection refused or Connection timed out or a MySQL specific CommunicationsException:
    Communications link failure
    , then it means that the DB isn’t reachable at all. This can have one or more of the following causes:

    1. IP address or hostname in JDBC URL is wrong.
    2. Hostname in JDBC URL is not recognized by local DNS server.
    3. Port number is missing or wrong in JDBC URL.
    4. DB server is down.
    5. DB server doesn’t accept TCP/IP connections.
    6. DB server has run out of connections.
    7. Something in between Java and DB is blocking connections, e.g. a firewall or proxy.

    To solve the one or the other, follow the following advices:

    1. Verify and test them with ping.
    2. Refresh DNS or use IP address in JDBC URL instead.
    3. Verify it based on my.cnf of MySQL DB.
    4. Start the DB.
    5. Verify if mysqld is started without the --skip-networking option.
    6. Restart the DB and fix your code accordingly that it closes connections in finally.
    7. Disable firewall and/or configure firewall/proxy to allow/forward the port.

    Update 2

    1. If your system is Windows, go to Start>>Run.
    2. Type command. This will open command prompt.
    3. Type “ping 192.168.1.61”
    4. You might get reply in below format.

    Pinging 192.168.1.61 [192.168.1.61] with 32 bytes of data:

    Reply from 192.168.1.61: bytes=32 time=101ms TTL=124

    If you don’t get something in above format, then your MYSQL Server with ip 192.168.1.61 is NOT REACHABLE. Ask your team to start the server first. 🙁

    If you have Linux version, open terminal and follow step 3.

    Also check below link. Those might help you…

    1. http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with java. I have an interface that has an annotated method in
I have working app1.ear , containing: JPA entity, MyObjectImpl , implementing interface MyObject from
I have some classes that all implement the same Java interface, which essentially allows
I'm working on a web interface for modifying Oracle database backup settings. One of
I am working with a programmer who is using Java to create an interface
I'm working on a application which has Java web interface hosted on Glassfish server
I'm working on OSGI bundle which uses Java native interface. I use this makefile
I am working on a Web App with Eclipse for Java EE. I have
This is language agnostic, but I'm working with Java currently. I have a class
I'm working on a standard Java system with critical timing requirements for my producers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.