包com.mysql.jdbc不存在

问题描述 投票:0回答:1

我在导入com.mysql.jdbc.Connection时遇到问题,它说包com.mysql.jdbc不存在,而iam已经将mysql-connector-java-5.1.36放在了netbeans上

    package pkgnew;
import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
 *
 * @author xxxx1
 */
public class DBConn {
    private Connection DBConn;
    public Connection connect() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("Connection Success");
        }
        catch(ClassNotFoundException cnfe){
            System.out.println("Connection Fail" + cnfe);
        }
        String url = "jdbc:mysql://localhost:3306/cars";
            try {
            DBConn = (Connection) DriverManager.getConnection(url, "root","123456");
            System.out.println("Database Connected");
            }
            catch (SQLException se){
                    System.out.println("No Database"+se);
                    }
            return DBConn;
        }
    }
java mysql jdbc
1个回答
0
投票

这是Jar缺少的问题。Netbean编辑器无法从MySQL_XXX_whatever_Name.jar进行分类。

请首先将正确要求的库添加到您的Java项目中。

In Netbean, Right click on Library -> search Mysql...jar file(if exist from list) otherwise, manually download and import.

您的问题将得到解决。

© www.soinside.com 2019 - 2024. All rights reserved.