?
Solved

No suitable driver found for jdbc:mysql

Posted on 2012-03-18
20
Medium Priority
?
3,041 Views
Last Modified: 2012-03-18
I am trying to run the program whose code is attached. I am getting an error about the driver. I read that "The MySQL JDBC driver is called Connector/J. (The driver class is org.gjt.mm.mysql.Driver.) " I have mysql-connector-java-5.1.18-bin.jar in the directory at C:\Program Files\Weka-3-7\mysql-connector-java-5.1.18\.

My classpath looks like this:
.;C:\Program Files\Weka-3-7\weka.jar;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\Program Files\Weka-3-7\mysql-connector-java-5.1.18\mysql-connector-java-5.1.18-bin.jar

The program compiles but when I try to run it I get this:

C:\Users\Bill\Desktop\test>java JavaWekaJ48TestTrainPredSQL
Trying to add database driver (JDBC): org.gjt.mm.mysql.Driver - Warning, not in CLASSPATH?
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:mysql://
mysql1003.ixwebhosting.com:3306/C261605_insidernet
        at java.sql.DriverManager.getConnection(DriverManager.java:604)
        at java.sql.DriverManager.getConnection(DriverManager.java:221)
        at weka.experiment.DatabaseUtils.connectToDatabase(DatabaseUtils.java:521)
        at weka.experiment.InstanceQuery.retrieveInstances(InstanceQuery.java:287)
        at weka.experiment.InstanceQuery.retrieveInstances(InstanceQuery.java:272)
        at JavaWekaJ48TestTrainPredSQL.main(JavaWekaJ48TestTrainPredSQL.java:53)

Can anyone say what is wrong here?
Thank you.
JavaWekaJ48TestTrainPredSQL.java
0
Comment
Question by:onyourmark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 7
20 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 37734269
this is strange name for MySql driver - it is probably not prsent in mysql-connector:
org.gjt.mm.mysql.Driver
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37734271
copy this file
mysql-connector-java-5.1.18-bin.jar

into a new folder and change its extension to .zip to

mysql-connector-java-5.1.18-bin.zip

then open ithwuith winzip and look if you find the class Driver and idf it is really sitting in all these folders:

 org/gjt/mm/mysql
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37734274
I used this name of the driver for MySQL:

JDBC Driver: com.mysql.jdbc.Driver
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:onyourmark
ID: 37734277
Thanks.

I unzipped it
C:\Users\Bill\Desktop\New folder (2)\org\gjt\mm\mysql
and there is
Driver.class

in there.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37734280
try download this file - findJar saya that the driver you are looking for is in this jar:

http://mirrors.ibiblio.org/pub/mirrors/maven2/mysql/mysql-connector-java/5.1.9/mysql-connector-java-5.1.9.jar
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37734286
show your connection code.
Do you have line

Class.forName("org.gjt.mm.mysql.Driver");

in there ?
0
 

Author Comment

by:onyourmark
ID: 37734294
Hi. Thanks. Here is the website for this driver
http://dev.mysql.com/downloads/connector/j/
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37734299
I think this is the good example - follow it strictly - and check I'm sure you have the
noraml driver  com.mysql.jdbc.Driver
also present in your jar.

http://www.roseindia.net/jdbc/jdbc-mysql/MysqlConnect.shtml


So follow this code and it should work:
import java.sql.*;

public class MysqlConnect{
  public static void main(String[] args) {
  System.out.println("MySQL Connect Example.");
  Connection conn = null;
  String url = "jdbc:mysql://localhost:3306/";
  String dbName = "jdbctutorial";
  String driver = "com.mysql.jdbc.Driver";
  String userName = "root"; 
  String password = "root";
  try {
  Class.forName(driver).newInstance();
  conn = DriverManager.getConnection(url+dbName,userName,password);
  System.out.println("Connected to the database");
  conn.close();
  System.out.println("Disconnected from database");
  } catch (Exception e) {
  e.printStackTrace();
  }
  }
}

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 37734302
yes, you web site is correct and jar is correct - that git.mm.... is the old way of calling this driver which is kept for compatibility.

Probably you have something incorrect in your actual code.

Anyway, I recommend that you follow structly thew example I posted above - I connected in this way to MySQL and uit should work
0
 

Author Comment

by:onyourmark
ID: 37734303
Thanks again. I am following this tutorial
http://weka.wikispaces.com/Use+WEKA+in+your+Java+code

and they say to make sure you have the  Connector/J from http://dev.mysql.com/downloads/connector/j/ 

and

Notes:
Don't forget to add the JDBC driver to your CLASSPATH.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37734309
The place form which you download is correct and your jar is fine - they are just using the old version of the driver; the newr one is the one I showed you.

The older one should alkso work but as you see it does not So try the one which is used now as a standard

Also post your actual connection code (similar to the piece which I posted) - maybe there is a mistake there

Did you write connection code yourself ?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37734311
how do you sepcify CLASsPATH?
did you type that command frok  the commad line?
0
 

Author Comment

by:onyourmark
ID: 37734314
No. I put it in the classpath variable in the environment variables.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37734316
go to your command line and print from the command line
echo %CLASSPATH% and post here
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37734318
Also post your actual connection code (similar to the piece which I posted) - maybe there is a mistake there

Did you write connection code yourself ?
0
 

Author Comment

by:onyourmark
ID: 37734328
C:\Users\Bill\Desktop\test>echo %CLASSPATH%
.;C:\Program Files\Weka-3-7\weka.jar;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\Progra
m Files\Weka-3-7\mysql-connector-java-5.1.18\mysql-connector-java-5.1.18-bin.jar

Now I tried again to run it (I closed the cmd window and reopened it) and I get
C:\Users\Bill\Desktop\test>java JavaWekaJ48TestTrainPredSQL
Exception in thread "main" java.lang.UnsupportedClassVersionError: JavaWekaJ48TestTrainPredS
QL : Unsupported major.minor version 51.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$000(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: JavaWekaJ48TestTrainPredSQL.  Program will exit.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37734331
Come on - that is your old issue - you are trying to run it with Java 6 though it was compiled iwth Java 7
change the PATH so that it should point to JDK7/bin
0
 

Author Comment

by:onyourmark
ID: 37734476
sorry :-(

Can I confirm, every time I make a change to a system variable through the control panel I have to close the command window and reopen it?

Also, whenever I open a new command window and I want to run a class file, I need to first call the setPath.bat code?

Now I think I am making some progress. It says "access denied for user 'nobody' using password: No. I guess I have to create a user for the database with read permission and then fill in with those credentials and try again?

Thanks.
0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 37734480
Can I confirm, every time I make a change to a system variable through the control panel I have to close the command window and reopen it?

YES

Also, whenever I open a new command window and I want to run a class file, I need to first call the setPath.bat code?

YES, it is safe to do it
Alternatively you can go to that control panel place and put that ....jdk7/bin path - at the
very beginning of your PATH - then it will always pick up both your java.exe and javac.exe  form that folder and you should not have problems with that


Now I think I am making some progress. It says "access denied for user 'nobody' using password: No. I guess I have to create a user for the database with read permission and then fill in with those credentials and try again?

YES, this means iot already accepted and used the driver calss
0
 

Author Closing Comment

by:onyourmark
ID: 37734526
YESSS!
It works. Thanks for your help!
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question