MySQL JDBC Driver ClassNotFound
Hi,
I have problem to make a connection to mySQL db
Here's the code in NetBeans 7
public class TestConnection {
public static void main(String[] argv) throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
if (!con.isClosed())
{
System.out.println("Connected");
con.close();
}
else {System.out.println("Not connected");}
}
}
I'm using XP n I have set the classpath in the system environment variable to the folder that hold the jar for msql connection.
However I get this error message :
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at TestConnection.main(TestConnection.java:14)
I've browsed the topics n see many things but mostly about classpath which I already set, so now in quite a confusion.
Anyway I intended to first check the connection to MySQL before anything else which I never do before.
I also use javac from command line with including -cp <path to mysql connection jar file> file.java....then run java file, also generating around the same error message
Thanks in advance