onyourmark
asked on
No suitable driver found for jdbc:mysql
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.1 8-bin.jar in the directory at C:\Program Files\Weka-3-7\mysql-conne ctor-java- 5.1.18\.
My classpath looks like this:
.;C:\Program Files\Weka-3-7\weka.jar;C: \Program Files\Java\jre6\lib\ext\QT Java.zip;C :\Program Files\Weka-3-7\mysql-conne ctor-java- 5.1.18\mys ql-connect or-java-5. 1.18-bin.j ar
The program compiles but when I try to run it I get this:
C:\Users\Bill\Desktop\test >java JavaWekaJ48TestTrainPredSQ L
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/C261 605_inside rnet
at java.sql.DriverManager.get Connection (DriverMan ager.java: 604)
at java.sql.DriverManager.get Connection (DriverMan ager.java: 221)
at weka.experiment.DatabaseUt ils.connec tToDatabas e(Database Utils.java :521)
at weka.experiment.InstanceQu ery.retrie veInstance s(Instance Query.java :287)
at weka.experiment.InstanceQu ery.retrie veInstance s(Instance Query.java :272)
at JavaWekaJ48TestTrainPredSQ L.main(Jav aWekaJ48Te stTrainPre dSQL.java: 53)
Can anyone say what is wrong here?
Thank you.
JavaWekaJ48TestTrainPredSQL.java
My classpath looks like this:
.;C:\Program Files\Weka-3-7\weka.jar;C:
The program compiles but when I try to run it I get this:
C:\Users\Bill\Desktop\test
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
at java.sql.DriverManager.get
at java.sql.DriverManager.get
at weka.experiment.DatabaseUt
at weka.experiment.InstanceQu
at weka.experiment.InstanceQu
at JavaWekaJ48TestTrainPredSQ
Can anyone say what is wrong here?
Thank you.
JavaWekaJ48TestTrainPredSQL.java
copy this file
mysql-connector-java-5.1.1 8-bin.jar
into a new folder and change its extension to .zip to
mysql-connector-java-5.1.1 8-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
mysql-connector-java-5.1.1
into a new folder and change its extension to .zip to
mysql-connector-java-5.1.1
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
I used this name of the driver for MySQL:
JDBC Driver: com.mysql.jdbc.Driver
JDBC Driver: com.mysql.jdbc.Driver
ASKER
Thanks.
I unzipped it
C:\Users\Bill\Desktop\New folder (2)\org\gjt\mm\mysql
and there is
Driver.class
in there.
I unzipped it
C:\Users\Bill\Desktop\New folder (2)\org\gjt\mm\mysql
and there is
Driver.class
in there.
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
http://mirrors.ibiblio.org/pub/mirrors/maven2/mysql/mysql-connector-java/5.1.9/mysql-connector-java-5.1.9.jar
show your connection code.
Do you have line
Class.forName("org.gjt.mm. mysql.Driv er");
in there ?
Do you have line
Class.forName("org.gjt.mm.
in there ?
ASKER
Hi. Thanks. Here is the website for this driver
http://dev.mysql.com/downloads/connector/j/
http://dev.mysql.com/downloads/connector/j/
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:
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();
}
}
}
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
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
ASKER
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.
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.
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 ?
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 ?
how do you sepcify CLASsPATH?
did you type that command frok the commad line?
did you type that command frok the commad line?
ASKER
No. I put it in the classpath variable in the environment variables.
go to your command line and print from the command line
echo %CLASSPATH% and post here
echo %CLASSPATH% and post here
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 ?
Did you write connection code yourself ?
ASKER
C:\Users\Bill\Desktop\test >echo %CLASSPATH%
.;C:\Program Files\Weka-3-7\weka.jar;C: \Program Files\Java\jre6\lib\ext\QT Java.zip;C :\Progra
m Files\Weka-3-7\mysql-conne ctor-java- 5.1.18\mys ql-connect or-java-5. 1.18-bin.j ar
Now I tried again to run it (I closed the cmd window and reopened it) and I get
C:\Users\Bill\Desktop\test >java JavaWekaJ48TestTrainPredSQ L
Exception in thread "main" java.lang.UnsupportedClass VersionErr or: JavaWekaJ48TestTrainPredS
QL : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defi neClass1(N ative Method)
at java.lang.ClassLoader.defi neClassCon d(Unknown Source)
at java.lang.ClassLoader.defi neClass(Un known Source)
at java.security.SecureClassL oader.defi neClass(Un known Source)
at java.net.URLClassLoader.de fineClass( Unknown Source)
at java.net.URLClassLoader.ac cess$000(U nknown Source)
at java.net.URLClassLoader$1. run(Unknow n Source)
at java.security.AccessContro ller.doPri vileged(Na tive Method)
at java.net.URLClassLoader.fi ndClass(Un known Source)
at java.lang.ClassLoader.load Class(Unkn own Source)
at sun.misc.Launcher$AppClass Loader.loa dClass(Unk nown Source)
at java.lang.ClassLoader.load Class(Unkn own Source)
Could not find the main class: JavaWekaJ48TestTrainPredSQ L. Program will exit.
.;C:\Program Files\Weka-3-7\weka.jar;C:
m Files\Weka-3-7\mysql-conne
Now I tried again to run it (I closed the cmd window and reopened it) and I get
C:\Users\Bill\Desktop\test
Exception in thread "main" java.lang.UnsupportedClass
QL : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defi
at java.lang.ClassLoader.defi
at java.lang.ClassLoader.defi
at java.security.SecureClassL
at java.net.URLClassLoader.de
at java.net.URLClassLoader.ac
at java.net.URLClassLoader$1.
at java.security.AccessContro
at java.net.URLClassLoader.fi
at java.lang.ClassLoader.load
at sun.misc.Launcher$AppClass
at java.lang.ClassLoader.load
Could not find the main class: JavaWekaJ48TestTrainPredSQ
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
change the PATH so that it should point to JDK7/bin
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
YESSS!
It works. Thanks for your help!
It works. Thanks for your help!
org.gjt.mm.mysql.Driver