• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connect to MySql with JDBC

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: java.net
.SocketException: Option unsupported by protocol: create
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1622)
at com.mysql.jdbc.Connection.<init>(Connection.java:491)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:346)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DataSource.<init>(DataSource.java:33)

Any help is appreciated.
Thanks,
Aidan
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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("org.gjt.mm.mysql.Driver"); // 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.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic