【问题标题】:How to handle the following Exception while connecting MySQL with Eclipse?连接 MySQL 和 Eclipse 时如何处理以下异常?
【发布时间】:2014-07-15 15:17:44
【问题描述】:

我是使用 Eclipse 的初学者。我正在使用 Eclipse LUNA 包和 MySQL 6.0 Workbench。我在引用库文件中粘贴了“mysql-connector-java-5.0.8-bin.jar”文件。我的编码如下:

    package a1;
    import java.util.Scanner;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    class a2 { 
    public static void main (String[] args) { 
    String dbURL = "jdbc:mysql://localhost:3306/test";
    String username ="root";
    String password = "root";   
    Connection dbCon = null;
    Statement stmt = null;
    ResultSet rs = null;   
    String query ="select * from k111";   
    try {
    dbCon = DriverManager.getConnection(dbURL, username, password);
    stmt = dbCon.prepareStatement(query);
    rs = stmt.executeQuery(query);
    System.out.println("Success");
    while(rs.next()){
    System.out.println(query);
    }
    }  
    catch(SQLException ex)
    {
    System.out.println(ex);
    }
    finally
    {
    rs.close();stmt.close();  dbCon.close();
    }     
    }}

我的数据库名称是“test”。我的表名是 k111。我只需要按照程序打印“Success”就可以知道数据库连接是否成功。但是,我的输出是

    java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test  

请指导我.......

【问题讨论】:

    标签: java mysql eclipse


    【解决方案1】:

    您的 jdbc URL 可能有误,请尝试以下操作:

    String dbURL = "jdbc:mysql://localhost:3306/test";   
    

    提供 url 到你的 mysql 文件夹

    【讨论】:

    • 这也不行......另外,我的数据库名称是“test”......所以只有我把test放在那个地方......我可以知道原因吗将其更改为“mysql”....????
    • 哦抱歉哈哈你可以看看stackoverflow.com/questions/2839321/…
    • 好的.....当我添加“Class.forName("com.mysql.jdbc.Driver");”在我的代码中,我清除了该异常........感谢您的友好回复
    • 对不起我的错误:)
    猜你喜欢
    • 2023-01-18
    • 1970-01-01
    • 2016-01-07
    • 2016-08-21
    • 1970-01-01
    • 2011-11-07
    • 2019-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多