连接 mysql 和 java

Connect mysql with java

我正在尝试连接到 java 中的 mysql(我使用 Wamp)所以我使用了以下代码:(我使用的是 Eclipse)

package genererPlanning;
import java.sql.*;

public class genererPlanning{
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://localhost/mysql";

    static final String USER = "root";
    static final String PASS = "";

    public static void main(String[] args){
        Connection conn = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root", "");
        }
        catch (SQLException ex){
            System.out.println("SQLException: " + ex.getMessage());
            System.out.println("SQLState: " + ex.getSQLState());
            System.out.println("VendorError: " + ex.getErrorCode());
        }
    }
}

但它返回了我这个文本:

SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mysql
SQLState: 08001
VendorError: 0

你知道为什么它不起作用吗?
PS:我查看了这些链接,但没有找到我的答案:
- Whosebug
- Whosebug
- Whosebug
- commentcamarche

谢谢大家。

您需要 mysql jdbc 连接器..从此 site

下载

您需要使用 mysql-connector.jar

这里是 link,其中包含有关如何将其设置为您的类路径的说明。

http://code.google.com/p/find-ur-pal/downloads/detail?name=mysql-connector-java-5.1.18-bin.jar&