This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Connecting to a remote mysql database  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());
}
}
}
}
}
 
Bartender
Posts: 9550
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No thats all sorted, its the error message with the driver thats the prob.
thanx anyway,
j.f.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Print out the classpath variable and ensure it has the mysql-connector-java~WhateverItsNameIs.jar.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!