java连不上mysql数据库了= =

代码如下
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JOptionPane;

public class mysql {

public static void main(String[] args) {
    String driver = "com.mysql.jdbc.Driver";  

    // URL指向要访问的数据库名
    String url = "jdbc:mysql://localhost:3306/test";  
    // MySQL配置时的用户名  
    String user = "root";  
    // Java连接MySQL配置时的密码  
    String password = "123456";  

    try {  

        // 加载驱动程序  
        Class.forName(driver);  

        // 连续数据库  
        Connection conn = DriverManager.getConnection(url, user, password);  

        if(!conn.isClosed())  
        System.out.println("Succeeded connecting to the Database!");  


    } catch(ClassNotFoundException e) {     
        System.out.println("Sorry,can`t find the Driver!");     
        e.printStackTrace();     
    } catch(SQLException e) {     
        e.printStackTrace();     
    } catch(Exception e) {     
        e.printStackTrace();     
    }     
}     

}

然后提示错误,
Sorry,can`t find the Driver!
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at mysql.main(mysql.java:25)
,怎么解啊//、

从报错来看是没有mysql数据库连接的驱动包,下载一个mysql-connector-java-5.0.4-bin.jar放到你的lib文件夹下面去再重新启动tomcat试试。

jdbc驱动没有找到,检查下com.mysql.jdbc.Driver有没有?

1.确定自己的mysql安装是否成功。
2.如果是集成开发工具开发,请在build path中加载jar包:mysql-connector-java-5.0.4-bin.jar,版本可以根据自己的需要选择。

图片说明

jdbc驱动没有找到,检查下com.mysql.jdbc.Driver有没有,看看你有没有这个包com.mysql.jdbc

驱动类没有加载到工程区,如果你是web工程,外链的jar包是无法进入工程区的,必须在工程内创建文件夹储存该jar包,jar包引用指向工程内部才能启动成功

去下载一个:JAVA连MySQL驱动mysql-connector-java-5.1.25.jar,添加到项目依赖中;
http://download.csdn.net/detail/testcs_dn/8435665

把这个文件放到你的项目下的\WEB-INF\lib目录中,然后回到Eclipse中刷新一下。

去官网下载与你mysql版本相匹配的JDBC驱动包,然后加到你的项目build path中。