Hi all,
I'm stumped and can't seem to find an answer on Google. I am running a java application through Eclipse and it connects to mysql. It connects fine if I run it through Eclipse but if I make a standalone jar file and then run it through Window's Vista command line then i get this error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at database.Connect.ConnectDB(Connect.java:16)
I have downloaded mysql-connector-java-5.1.16-bin.jar file and placed it in the classpath and path environment variables.
I have also included it as an external jar file in the libraries section of Eclipse->Project->Properties->Java Build Path and also in Window->Preferences->Classpath Variables
But I still get the above error. This is my connect code:
package database;
import java.sql.Connection;
import java.sql.DriverManager;
public class Connect {
public Connection ConnectDB()
{
Connection conn = null;
try
{
String userName = "root";
String password = "planet";
String url = "jdbc:mysql://localhost:3306/test";
Class.forName ("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
e.printStackTrace();
}
return (conn);
}
}
Please help. Thanks so much :)