找不到com.mysql.jdbc.Driver
我用mysql创建了个student表,然后mysql服务也启动了用myeclipse加载驱动是说找不到,问下原因,代码下面:
package hcl;
import java.sql.*;
public class test {
public static void main(String[] args) {
try{
Class.forName("com.mysql.jdbc.Driver"); //加载驱动
Connection con=DriverManager.getConnection("jdbc:mysql://localhos:3306/student", "root", "root");
//说明数据库URL,链接数据库
Statement stm=con.createStatement();
String str="select * from student;"; //构造SQL语句
stm.executeUpdate(str);
ResultSet rs=stm.executeQuery(str);
while(rs.next()){ //执行结果
System.out.print(rs.getInt(1)+" ");
System.out.print(rs.getString(2)+" ");
System.out.print(rs.getInt(3)+" ");
System.out.println(rs.getInt(4));
}
stm.close();
con.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at (Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at (Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at hcl.test.main(test.java:9)