MySqlProblem ClassNotFound
Hi,Seniors:
I'm a fresh who are newly to jdbc. I write my first toyprogram to connect mysql database and have errors. the code as follows:
import java.sql.*;
public class TestJDBC {
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.driver").newInstance ();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/MyData?" +
"user=root&password=20032206");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("Select * from dept");
while(rs.next()) {
System.out.println(rs.getString("deptno"));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
and console response as follows:
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 07)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at TestJDBC.main(TestJDBC.java:8)
10
20
30
40
50
60
My puzzle is I have connected to DB succesfully. But why ClassNotFound Exception exist? I hope for answers . thanks