aspose file tools*
The moose likes JDBC 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
Bookmark "Connecting to a remote mysql database" Watch "Connecting to a remote mysql database" New topic
Author

Connecting to a remote mysql database

john flowers
Greenhorn

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 'http://mmmysql.sourceforge.net/' 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;
try{
String url = "jdbc://hostname:3306/database";
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection(url, "uname", "pwd");
if(con != null){
System.out.println("whehe");
}
}
finally{
if(con != null){
try{
con.close();
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
}
}
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8895
    
    8

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?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[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
Greenhorn

Joined: Jan 26, 2004
Posts: 3
No thats all sorted, its the error message with the driver thats the prob.
thanx anyway,
j.f.
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: http://aspose.com/file-tools
 
subject: Connecting to a remote mysql database