-1

Please I have a Java Desktop app which connects to a MySQL database and I would like to run the application over a network.

This is what I've done so far. My Java application generates a batch file that points to the original local of the .jar file so I simply place this batch file in other client systems and run them so they simply find the .jar file on the server system and open the application.

But I have an issue, I have a scenario where I don't know the server's system name so I can't specify it in the MySQL database connection string.

Please how can I dynamically get the system name and pass it into the database connection string so the client systems can also connect to the same server or database?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Andrew
  • 19
  • 7
  • You have to know your target server somehow to address him if you don't want to implement some kind of broadcast/detection mechanism. – Smutje Feb 11 '15 at 07:58
  • Could you launch the `.jar` file with command line arguments? `java -jar myjar.jar -server 10.0.10.100` You could then parse these arguments in your main method. – Matt Clark Feb 11 '15 at 08:01
  • I don't seem to understand you. But what if I write the server name into a text file and try reading it from the client system.... Again I'm getting the system name dynamically so the path specified would have to be different too. How do I achieve this? – Andrew Feb 11 '15 at 08:04

2 Answers2

0

you may find it useful if you want to know how could we get username of any host System.getProperty("user.name") returns HOSTNAME instead of currently logged username

Community
  • 1
  • 1
prasanth
  • 3
  • 5
0

This may help you

 import java.net.InetAddress;

Code

String myip=(InetAddress.getLocalHost()).toString();

Here you will get pc name and ip address with a '/' separated

 String data[]=myip.split("/");

        System.out.println(data[0]);  // Machine name
        System.out.println(data[1]);  //Ip address
Anptk
  • 1,125
  • 2
  • 17
  • 28