2

I tried to use the following connection

URL oracle = new URL("http://www.oracle.com/");
    URLConnection yc = oracle.openConnection(); 
    yc.setConnectTimeout(100000);
    BufferedReader in = new BufferedReader(new InputStreamReader(
                                yc.getInputStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null) 
        System.out.println(inputLine);
    in.close();

It throws java.net.UnknownHostException

I cannot set mapping in system32\drivers\etc\hosts . And I cannot make any changes there . Is there any way to overcome this ? It works on my other computer, but does not on the one want to use it on


i tried using

searchUrl="http://96.7.228.140/";

And got the following error

java.net.ConnectException: Connection timed out: connect
Buras
  • 3,069
  • 28
  • 79
  • 126
  • Why do you want to add this to your hosts file? Is it not resolvable through DNS? What if you do your own substitution of the numeric IP address for the host name in the URL? – Chris Stratton Apr 09 '14 at 15:26
  • How do i do this ? searchUrl="123.45.67.89"; – Buras Apr 09 '14 at 15:33
  • `http://123.45.67.89/somefile.html` - though some kinds of multiple-sites-per-server schemes won't work without knowing the name of the server you are seeking. – Chris Stratton Apr 09 '14 at 15:40
  • Looks like this computer is not configured correctly. Unless you fix that how wil you deal with cases when oracle drops that IP? Not the only way, but one way to resolve is hit a open dns your self and get the IP but looks like even if you give the IP it does not work – tgkprog Apr 09 '14 at 18:06

1 Answers1

1

You already tried substituting the domain name with the IP in the URL and it didn't work. That indicates there's a different problem. Most likely not a java problem. You shouldn't try to fix it using the hosts file.

If you can ping oracle.com then Java should be able to connect to it.

The only issue could be on the length of the connection, as your connection might be timing out if your network is too slow.

Do a ping on oracle.com and check what is the time it takes for them to respond. Adjust your connection timeout accordingly.

If that doesn't work, you might have a firewall problem in the other computer. Either that or your network adapter is not properly installed.

Can you open an internet browser on the machine and navigate to http://www.oracle.com?

If you can, then try your program. If it doesn't work then check the connection time.

Alexandre Santos
  • 8,170
  • 10
  • 42
  • 64