当我尝试运行我的代码时,出现了异常java.lang.ClassNotFoundException
。
我的代码:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/simple",
"root","root");
Statement stmt=con.createStatement();
String query="SELECT * FROM CUST";
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
System.out.print(rs.getString("CUST_NAME") +" ");
System.out.print(rs.getString(2) +" ");
System.out.print(rs.getString(3) +" ");
}
rs.close();
stmt.close();
con.close();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch (SQLException e)
{
e.printStackTrace();
}
我遇到了错误
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 Simple.MyProg.main(MyProg.java:15)
我做错了什么?