Java &引用;ClassNotFoundException:com.mysql.jdbc.Driver“;

Java &引用;ClassNotFoundException:com.mysql.jdbc.Driver“;,java,jdbc,database-connection,classnotfoundexception,Java,Jdbc,Database Connection,Classnotfoundexception,我刚使用Intellij13,在连接MySQL时遇到了问题。我正在使用下面的代码,这是我从教程中学习的代码,使用IntelliJ IDEA 12管理您的数据库方案 public class App { public static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; public static final String JDBC_URL = "jdbc:mysql://localhost/sample";

我刚使用Intellij13,在连接MySQL时遇到了问题。我正在使用下面的代码,这是我从教程中学习的代码,使用IntelliJ IDEA 12管理您的数据库方案

public class App {

    public static  final  String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    public static final String JDBC_URL = "jdbc:mysql://localhost/sample";
    public static final String JDBC_USER = "root";
    public static final String JDBC_PASSWORD = "";

    public static void main (String[] args) throws SQLException, ClassNotFoundException {
        Statement statement = null;
        try{
            Class.forName(JDBC_DRIVER);
            Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery("select id, firstname, lastname, email " +
                    "from customer");
            System.out.println("First name\tLast name\tEmail");
            int count = 0;
            while (resultSet.next()){
                String firstname = resultSet.getString("firstname");
                String lastname = resultSet.getString("lastname");
                String email = resultSet.getString("email");
                System.out.printf("%s\t%s\t%s%n", firstname, lastname, email);
                count++;
            }
            System.out.println("--");
            System.out.println(MessageFormat.format("Rows: {0}", count));
        } finally {
            if(statement != null){
                statement.close();
            }
        }
    }
}
基于这个问题,我已经尝试了很多解决方案,但是没有什么能解决我的问题。 它会给出这样的错误消息

Connection to MySQL – sample@localhost failed: Exception in thread “main” 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:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at com.intellij.persistence.database.console.RemoteJdbcServer.main(RemoteJdbcServer.java:15)
我也遵循这一点来解决我的问题,但即使问题是一样的,也没有什么对我有效。
. 实际上,我想在Intellij13上使用MySQL创建数据库,但与MySQL的连接失败。我试图通过将mysql-connector-java-5.1.26-bin.jar放在项目结构中来解决这个问题,但这对我不起作用。我不知道如何解决这个问题?我希望这个问题上的一些专家能帮助我解决这个问题。
我不能用这个评论,我不知道为什么。所以我在这里回答。Ashish:我已经下载了jar文件,但是我不知道把这些文件放在哪里。你有主意吗?

你需要下载包含
com.mysql.jdbc.Driver的jar

所以你可以从这里开始,然后设置你的
类路径

在“相关”问题上取得一个峰值。试着将catch块和finally块一起添加,然后打印堆栈跟踪。“我试图通过将mysql-connector-java-5.1.26-bin.jar放入项目结构中来解决这个问题”-我不知道IntelliJ,但在Eclipse中,这不一定与将jar添加到项目类路径或引用库相同。