This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Connect to MySql with JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connect to MySql with JDBC" Watch "Connect to MySql with JDBC" New topic

Connect to MySql with JDBC

Aidan Mooney

Joined: Sep 04, 2003
Posts: 1
I am trying to connected to a MySql database using jdbc. I have set up the database that I am trying to connect to. I have some Java code which is simply trying to connect to the database. However I get the following error and was hoping someone would be able to help me out with it.
java.sql.SQLException: Unable to connect to any hosts due to exception:
.SocketException: Option unsupported by protocol: create
at com.mysql.jdbc.Connection.createNewIO(
at com.mysql.jdbc.Connection.<init>(
at com.mysql.jdbc.NonRegisteringDriver.connect(
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DataSource.<init>(

Any help is appreciated.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299

If you could supply us with your code, we can help. Error messages don't mean much without the associated code that goes with them.
Be sure and use the UBB Code Block tags to make things easier to read.

GenRocket - Experts at Building Test Data
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Things to check for:
  • Make sure that the "mysql" JDBC drivers are in your class path
  • In your code, register the driver:

  • Class.forName("com.mysql.jdbc.Driver"); // new driver
    ... or ...
    Class.forName(""); // old driver
  • Make sure the URL is correctly specified:

  • "jdbc:mysql://ip-address/database"

    You can register the drivers explicitly (as in above example), or as a run-time attribute when you start the program.
    You can use the IP address or DNS name in the URL, and the database is optional, though I like to specify it.
    If these suggestions don't work, please provide a code snippet and information about where the databse is.
    Don't get me started about those stupid light bulbs.
    subject: Connect to MySql with JDBC
    Similar Threads
    Hibernate Dialect for MS Access
    How to tell which port mySQL is running on?
    Mysql/JDBC Access Denied Error
    java.policy setting not reflecting
    MySQL 4.1 [ Connection refused]