Results 1 to 4 of 4
Thread: MySqlProblem ClassNotFound
- 05-13-2010, 06:23 AM #1
Member
- Join Date
- May 2010
- Posts
- 9
- Rep Power
- 0
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
- 05-13-2010, 06:25 AM #2
Member
- Join Date
- May 2010
- Posts
- 9
- Rep Power
- 0
Something addition: 10 20 30 40 50 60 are data I retrieve from database;
And I hope I can join in a java group in msn, that will be easy for discuss.
- 05-13-2010, 07:12 AM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
The driver class name starts with a capital D. You should have used "com.mysql.jdbc.Driver"
- 05-13-2010, 10:31 AM #4
Member
- Join Date
- May 2010
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
ClassNotFound exception for inner class
By hirop35 in forum New To JavaReplies: 0Last Post: 11-30-2009, 05:25 AM -
Client to Server, ClassNotFound Package Problem
By pwnzer in forum New To JavaReplies: 3Last Post: 11-07-2009, 09:17 PM -
ClassNotFound.com, as the name suggests, helps to avoid ClassNotFoundException in yo
By kalluriravi in forum Reviews / AdvertisingReplies: 0Last Post: 10-12-2009, 05:39 AM -
classnotfound
By mirror666 in forum New To JavaReplies: 1Last Post: 11-11-2008, 02:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks