public class studentdao { public student getstudent() throws Exception{ Class.forName("com.mysql.jdbc.Driver"); Connection conn=DriverManager.getConnection("jdbc:Mysql://localhost:3306/test","root", "123"); Statement stm=conn.createStatement(); ResultSet rs=stm.executeQuery("select * from student where id=2"); student stu=new student();
public class student { private long id; private String name; private String password;
public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; }
} 然后现在mysql的驱动包也导入了 数据库test里建了一张表student 里面有id=2的记录 还是一直报错 错误如下: Exception in thread "main" 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 com.studentdao.getstudent(studentdao.java:9) at com.studentdao.main(studentdao.java:33) 想问下到底是什么原因 我java一直都学不好 请高人指导下 谢谢啦!