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 7643261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:24:15+00:00 2026-05-31T09:24:15+00:00

TL;DR: Every time I try to use JDBC to connect to a local MySQL

  • 0

TL;DR:

Every time I try to use JDBC to connect to a local MySQL server (that works on tons of other sql clients), it doesn’t connect at all and I get an exception:

  • Exception in thread “main” com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
  • …. stack trace ….
  • Caused by: java.net.SocketException: Invalid argument: connect

More detailed info:

I’ve got a local MySQL server running that I can connect to with using the following info:

  • address: localhost or 127.0.0.1 (both work)
  • port: 3306
  • and my username/password/db name

Using the applications: HeidiSQL, phpmyadmin, MySQL Workbench and mysqladmin

Running mysqladmin version confirms that the server is up, working, and has tcp/ip enabled.

Doing mysqladmin variables shows that “skip_networking” is off (see below for full config).

The MySQL log shows nothing out of the ordinary (also below).

I’m using JDBC connector v5.1.15, mysql-connector-java-5.1.15-bin.jar. It’s in my project class path with Eclipse.

All windows 7 (Ultimate, 64bit if it matters) firewalls are off.

Yet I still get the stack trace error as shown below. I can’t for the life of me figure out what’s wrong when everything else is able to connect just fine…

I’ve tried to include all relevant information below. I’m hoping it’s just something simple and stupid that I’ve overlooked and can’t find because I’m looking too hard…but eh who knows :/ heh.

I’ve tried everything I’ve been able to find in other similar questions online but nothing seems to work (incl. https://stackoverflow.com/a/2985169/211750 , https://stackoverflow.com/a/2103092/211750 , https://serverfault.com/questions/89955/unable-to-connect-to-mysql-through-jdbc-connector-through-tomcat-or-externally and others)

My test code:

package sqltest;


import com.mysql.jdbc.Driver;
import java.sql.DriverManager;
import java.util.Properties;

public class main {

    public static void main(String[] args) throws Exception {
        String url = "jdbc:mysql://localhost:3306/dbname?user=user&password=****&";        

        Driver driver = (Driver) Class.forName("com.mysql.jdbc.Driver").newInstance();

        DriverManager.getConnection(url);
    }

}

Stack trace: http://pastebin.com/qv332y86

MySQL variables dump: http://pastebin.com/merSEDdD

My.ini: http://pastebin.com/EWZX2enz

MySQL mysqladmin version:

Server version          5.5.20-log
Protocol version        10
Connection              localhost via TCP/IP
TCP port                3306
Uptime:                 1 min 37 sec

Threads: 1  Questions: 17  Slow queries: 0  Opens: 33  Flush tables: 1  Open tables: 26  Queries per second avg: 0.175

MySQL log:

120314 21:37:20 [Note] Plugin 'FEDERATED' is disabled.
120314 21:37:20 InnoDB: The InnoDB memory heap is disabled
120314 21:37:20 InnoDB: Mutexes and rw_locks use Windows interlocked functions
120314 21:37:20 InnoDB: Compressed tables use zlib 1.2.3
120314 21:37:20 InnoDB: Initializing buffer pool, size = 128.0M
120314 21:37:20 InnoDB: Completed initialization of buffer pool
120314 21:37:20 InnoDB: highest supported file format is Barracuda.
120314 21:37:20  InnoDB: Waiting for the background threads to start
120314 21:37:21 InnoDB: 1.1.8 started; log sequence number 1619921
120314 21:37:21 [Note] Event Scheduler: Loaded 0 events
120314 21:37:21 [Note] wampmysqld: ready for connections.
Version: '5.5.20-log'  socket: ''  port: 3306  MySQL Community Server (GPL)
120314 21:38:02 [Note] wampmysqld: Normal shutdown

120314 21:38:02 [Note] Event Scheduler: Purging the queue. 0 events
120314 21:38:02  InnoDB: Starting shutdown...
120314 21:38:02  InnoDB: Shutdown completed; log sequence number 1619921
120314 21:38:02 [Note] wampmysqld: Shutdown complete
  • 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-31T09:24:17+00:00Added an answer on May 31, 2026 at 9:24 am

    Turned out it was Java preferring IPv6 messing things up so I had to add -Djava.net.preferIPv4Stack=true, but since I was running things under tomcat I had to go through a round-about way of setting the property. I’m not sure what the standard way of doing it is (if any) but I got it working by editing Catalina.bat and adding -Djava.net.preferIPv4Stack=true to the end of the file. See:

    rem Execute Java with the applicable properties
    if not "%JPDA%" == "" goto doJpda
    if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity
    %_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.net.preferIPv4Stack=true -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
    goto end
    :doSecurity
    %_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.net.preferIPv4Stack=true -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
    goto end
    :doJpda
    if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda
    %_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %JPDA_OPTS% %DEBUG_OPTS% -Djava.net.preferIPv4Stack=true -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
    goto end
    :doSecurityJpda
    %_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %JPDA_OPTS% %DEBUG_OPTS% -Djava.net.preferIPv4Stack=true -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
    goto end
    
    :end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My script does not seem to be working. Every time i try to use
I have one particular FLA that is crashing every time I try to compile
Every time I try to use my add function and return a list from
Every time I try to use Export, I get this Error: General::unavail: Export is
Every time I try to use z-index in a webpage to change the order
Regular Expressions kick my pants every time I try to use them. I'm using
Every time I try to make my amazon site use a .php index file
I'm getting a classCastException every time I try to use this preference class, and
If my file stream is in use (every time I try to debug, it
i've looked online but every time i try to connect to the localhost it

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.