Windoze7 Java7 issues with IP6

Post date: Jan 12, 2013 12:41:07 AM

I recently ran into a networking "issue" that was causing my JDBC data queries to not connect to their servers.

    • I kept getting an SQL error: java.sql.SQLException: The Network Adapter could not establish the connection This came out of (what I thought was) no-where because the commandline app previously worked fine.I was running an SQL based commandline app that was accessing an Oracle database.
    • I was using a Windoze 7 computer with Java 7 installed.
    • A native windows based port scan apps found the oracle 1521 port listening successfully (whereas my java based port scanner failed)
    • I was running through a VPN
  • Hmmmm, what is going on I tried all kinds of things to fix it, including setting the SERVER=DEDICATED on the JDBC connection Nothing worked, until... I backed out my JDK7 install and tried running it with Java 6.It worked again!
Java Logo

I did a bit more digging and found someone else with a similar network problem related to IP6

that got fixed by adding

  • -Djava.net.preferIPv4Stack=true

to the commandline, so I went back to Java7, added that define to my commandline and

  • everything worked again in Java7!

After reading the Oracle Java docs on this subject - http://docs.oracle.com/javase/6/docs/technotes/guides/net/ipv6_guide/index.html

I think this is actually a Windoze 7 thing, because Java transparently uses what is given to in the underlying system. My code has no specific requests for IP6 or IP4 for that matter.