【问题标题】:Cannot connect to MySQl database from Eclipse DataSource Explorer无法从 Eclipse DataSource Explorer 连接到 MySQl 数据库
【发布时间】:2012-03-14 08:11:41
【问题描述】:

http://motionsharing.com/site/download/acefad55f1e81e456d71a7448b278915

无法从 Eclipse DataSource Explorer 连接到 MySQl 数据库。

我调整了适当的驱动程序,但无法连接。 P.S.:我可以连接到 derby db,也可以连接到 mysql db,但只能通过代码连接,但我想从 Data Source Explorer 连接到 mysql db,以获得创建表等的可能性。

怎么了?

我可以通过代码连接。

public static void main(String args[]) {
    try {
        Class.forName("com.mysql.jdbc.Driver");
        System.out.println("Driver loading success!");
        String url = "jdbc:mysql://localhost:3306/mydb";
        String name = "root";
        String password = "root";
        try {
            Connection con = DriverManager.getConnection(url, name, password);
            System.out.println("Connected.");
            con.close();
            System.out.println("Disconnected.");
        } catch (SQLException e) {
            e.printStackTrace();
        }

    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

【问题讨论】:

    标签: java eclipse jakarta-ee jdbc


    【解决方案1】:

    您需要download MySQL JDBC驱动并将其添加到设置中。

    当您尝试在数据源资源管理器中创建新的连接配置文件时,您将看到这些屏幕。在最后一步中,您必须指向正确下载的 JAR 文件。

    【讨论】:

    • 那么 com.mysql.jdbc.Driver 是什么?
    • 是一个连接MySQL数据库的库。如果您从我发布的链接下载,您会找到它。
    【解决方案2】:

    在驱动程序属性中确保使用:

    URL: jdbc:mysql://localhost:3306/schema_name
    
    Database: schema_name
    

    因此 Eclipse 将在 Data Source Explorer 中显示表格。

    【讨论】:

    • 没有schema_name附加在URL末尾,表格节点不会展开,虽然它仍然可以显示表格节点但不能展开,很好的答案!
    猜你喜欢
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    • 2014-03-15
    • 2019-04-11
    • 2016-09-30
    • 2010-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多