JDBC and IPv6?

Discussion in 'Java' started by spacerook, Apr 12, 2007.

  1. spacerook

    spacerook Guest

    Has anyone ever made a JDBC connection using an IPv6 URL? I am
    setting my URL like so (the address here is fake):

    jdbc:mysql://[1111:2222:3333:4444:5555:6666:7777:8888]/mysql

    This results in the following error:

    Cannot get connection for URL jdbc:mysql://
    [1111:2222:3333:4444:5555:6666:7777:8888]/mysql : Illegal connection
    port value ':5555:6666:7777:8888]'

    I am trying to connect to a MySQL database and am using the MySQL
    drivers. The Java program is on a Windows machine, which has IPv6
    enabled and can successfully make a IPv6 ping (using ping6) to the
    MySQL server. I'm starting Java with -
    Djava.net.preferIPv6Addresses=true, which seems to have had no effect.
     
    spacerook, Apr 12, 2007
    #1
    1. Advertisements

  2. wrote in @n59g2000hsh.googlegroups.com:
    What happens when you use a fully-qualified domain name that resolves to the
    IPv6 IP address via DNS?

    I'd also recommend removing the square brackets surrounding the IPv6 address
    in the URL.

    Cheers!

    --
    ---------------------------------------------------------------------
    Greg R. Broderick

    A. Top posters.
    Q. What is the most annoying thing on Usenet?
    ---------------------------------------------------------------------
     
    Greg R. Broderick, Apr 12, 2007
    #2
    1. Advertisements

  3. spacerook

    a24900 Guest

    My understanding is that mysql's jdbc driver can't handle the numeric
    IPv6 address (postgress has a patched driver which can). mysql should
    work with a domain name, resolved to an IPv6 address. You don't have
    to put the IPv6 address into a DNS server to get it resolved. Putting
    the mapping into the local "hosts" file (on systems with a resolver
    which uses the file, too) should do.
     
    a24900, Apr 12, 2007
    #3
  4. The square brackets are there to indicate that the URL contains an
    IPv6 literal address.

    See rfc2732 (http://www.ietf.org/rfc/rfc2732.txt).

    /gordon

    --
     
    Gordon Beaton, Apr 13, 2007
    #4
  5. spacerook

    spacerook Guest

    This seems to be morphing into more of a MySQL problem now...

    I added an IPv6 address/hostname to my Windows host file. I can use
    ping6 on the hostname and it works. Good. But I am now getting a
    "Connection Refused" exception when trying to connect to the MySQL
    server on the Linux machine.

    I tried some experiments on the MySQL Linux box. This command works:

    mysql -h 127.0.0.1

    But this command gives an error:

    mysql -h ::1
    "Unknown MySQL Server host '::1'"

    I think if I can get that second statement to work (i.e. get the MySQL
    server to recognize IPv6 addresses), my problem will be solved.
     
    spacerook, Apr 13, 2007
    #5
  6. spacerook

    CsuElites Guest

    jdbc:mysql://[1111:2222:3333:4444:5555:6666:7777:8888]/mysql



    Today ,for the first time ,i konw the format of IPV6 address.Thanks!
     
    CsuElites, Apr 13, 2007
    #6
  7. spacerook

    TheAshwaniK

    Joined:
    Jan 11, 2011
    Messages:
    2
    Likes Received:
    0
    NOTE: THIS IS NOT A FIX, MYSQL CAN HANDLE THIS IN NEXT RELEASE IF THEY WANT. CHECK LICENCING BEFORE MODIFYING THE SRC CODE.

    I think the Mysql JDBC connector does not support the IPv6 Type of addresses.

    tried some reverse engineering and experimenting with the mysql JDBC connector source code, I found that it could support IPv6 after all.

    mysql-connector-java-5.1.14-bin.jar,class at com.mysql.jdbc/NonRegisteringDriver.java

    If you see the code inside function parseHostPortPair(),code is responsible for parsing the host port.since our IPv6 contains multiple colon ":",it fails

    protected static String[] parseHostPortPair(String hostPortPair) throws SQLException {
    ...
    if (portIndex != -1)
    {
    if (portIndex + 1 < hostPortPair.length())
    {
    String portAsString = hostPortPair.substring(portIndex + 1);
    hostname = hostPortPair.substring(0, portIndex);
    splitValues[0] = "hostname";
    splitValues[1] = portAsString;
    }
    else
    { throw SQLError.createSQLException(); } } ...

    Experiment

    Hard code your IPv6 address here splitValues[0] = "fe80::5ed6:baff:fe14:a23e"; and splitValues[1] = null;

    ActualFix:To be figured out. How to parse the IPv6 address contianing colons ":"

    And see It works :D
     
    TheAshwaniK, Jan 12, 2011
    #7
  8. spacerook

    TheAshwaniK

    Joined:
    Jan 11, 2011
    Messages:
    2
    Likes Received:
    0
    Thanks to Mark.
    We could make connection to Ipv6 address in a different way with no code changes anywhere.

    Read URL : bugs.mysql.com/bug.php?id=8836

    in the end ,a comment by Mark Mathew.
     
    TheAshwaniK, Jan 12, 2011
    #8
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.