File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Connecting to a remote mysql database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Connecting to a remote mysql database" Watch "Connecting to a remote mysql database" New topic

Connecting to a remote mysql database

john flowers

Joined: Jan 26, 2004
Posts: 3
hi all,
I have tried using this code to access a mysql database but alas i get an error 'Exception in thread "main" java.sql.SQLException: No sutible driver'
but I installed the driver from '' and set the CLASSPATH up correctly!?
Here is the code
import java.sql.*;
public class Connect{
public static void main(String args[]) throws Exception{
Connection con = null;
String url = "jdbc://hostname:3306/database";
con = DriverManager.getConnection(url, "uname", "pwd");
if(con != null){
if(con != null){
}catch(Exception e){
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

Just trying to rule out the obvious. In the following string:

You replace "hostname" with the host name of the computer the database resides on and "database" with the name of the database you are attempting to open, right?

[How To Ask Questions On JavaRanch]
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
URL should be:
String url = "jdbc:mysql://hostname:3306/database";
making sure you do what Joe suggested in terms of the hostname and database.
john flowers

Joined: Jan 26, 2004
Posts: 3
No thats all sorted, its the error message with the driver thats the prob.
thanx anyway,
Lu Battist
Ranch Hand

Joined: Feb 17, 2003
Posts: 104
Print out the classpath variable and ensure it has the mysql-connector-java~WhateverItsNameIs.jar.
I agree. Here's the link:
subject: Connecting to a remote mysql database
It's not a secret anymore!