Cant connect to mysql server
I have been trying unsuccesfully for the last day to connec to the mysql database from my java application.
I am using the NetBeans IDE and the connector is in the ide's classpath. (version 3.1 mysql connector)
I am runing xampp for linux as the development environment.My operating system is suse 10.0 and i am running java 1.4.2
The code I am using to test if the connector works properly is as follows.
import java.sql.*;
public class Main
{
public static void main (String[] args)
{
Connection conn = null;
try
{
String userName = "librarian";
String password = "MyPassword";
String url = "jdbc:mysql://localhost/project";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.err.println ("Exception "+ e.getMessage());
e.printStackTrace();
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}
When i compile and run it the output is as follows.
Exception com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at Main.main(Main.java:14)
Thank you all for helping me if you can.

