hey there,
I am trying to make my first connection to a mysql server with java. I took the following code from another thread:
import java.sql.Connection;
import java.sql.DriverManager;
public class Connect {
public static Connection ConnectDB()
{
Connection conn = null;
try
{
String userName = "root";
String password = "";
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);
}
public static void main(String[] args){
ConnectDB();
}
}
it compiles well, but when I run the code, I cat the following complaint:
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.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at Connect.ConnectDB(Connect.java:16)
at Connect.main(Connect.java:28)
how do I go about making the com.mysql.jdbc.Driver available. is it something I need to download and install separately from JDK or is it something that comes with JDK but I am not knowing how to use. please help!