Java连接MySQL有错误Sorry,can`tfindtheDriver!,请各位看一下
这是提示的错误
Sorry,can`tfindtheDriver!
java.lang.ClassNotFoundException:com.mysql.jdbc.Driver
atjava.net.URLClassLoader$1.run(UnknownSource)
atjava.net.URLClassLoader$1.run(UnknownSource)
atjava.security.AccessController.doPrivileged(NativeMethod)
atjava.net.URLClassLoader.findClass(UnknownSource)
atjava.lang.ClassLoader.loadClass(UnknownSource)
atsun.misc.Launcher$AppClassLoader.loadClass(UnknownSource)
atjava.lang.ClassLoader.loadClass(UnknownSource)
atjava.lang.Class.forName0(NativeMethod)
atjava.lang.Class.forName(UnknownSource)
atJDBCTest.main(JDBCTest.java:11)
下面是Java代码
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
publicclassJDBCTest{
publicstaticvoidmain(String[]args){
try{
//加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
//URL指向要访问的数据库名test
Stringurl="jdbc:mysql://127.0.0.1:3306/test";
//MySQL配置时的用户名
Stringuser="root";
//MySQL配置时的密码
Stringpassword="123456";
//连续数据库
Connectionconnection=DriverManager.getConnection(url,user,password);
if(!connection.isClosed())
System.out.println("SucceededconnectingtotheDatabase!");
//statement用来执行SQL语句
Statementstatement=connection.createStatement();
//要执行的SQL语句
Stringsql="select*fromstudent";
//执行SQL语句并返回结果集
ResultSetrs=statement.executeQuery(sql);
System.out.println("学号"+"t"+"姓名");
Stringname=null;
while(rs.next()){
//选择sname这列数据
name=rs.getString("sname");
//输出结果
System.out.prin