• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trouble connecting to an online database with java driver error

 
David Mesman
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, I just started on an program/app to connect to an online database! I found some stuff online on how to do it. The problem is that java can't find the driver for my online database (sql6.freedatabase.com is the host i'm using). Is there a standard driver for online databases for java or do I need something specific? Here is a part of my code that should connect with the database:

The error that I get is: "No suitable driver found for jdbc:mysql:sql6.freesqldatabase.com".
Thanks in advance!
 
Ron McLeod
Bartender
Pie
Posts: 1049
65
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They use MySQL, so you will need to use the MySQL JDBC driver.

Besides adding the jar to your project, you may also need to manually register the driver:
    Class.forName("com.mysql.jdbc.Driver")
 
David Mesman
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got that one already! It worked fine with my local database (xampp) without registering the class. I'll try to register the class and see what happens! Where do i place this line ?
 
Ron McLeod
Bartender
Pie
Posts: 1049
65
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Mesman wrote:.. Where do i place this line

In the com.mysql.jdbc.Driver class, there is a static initialiser block which contains code to register the driver with the DriverManager, so you will need to load the driver class somewhere before you call DriverManager.getConnection()

com.mysql.jdbc.Driver
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That JDBC connection string is not a mysql connectorJ one.

The proper format would be something like:
jdbc:mysql://sql6.freesqldatabase.com/{database name}

You may or may not need a port, depending on how the db has been set up.

Connector-J is a type 4 driver, so you do not need the Class.forName() at all.
 
David Mesman
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dave! That did the trick! The topic is now closed! Thanks for all the answers!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic