【问题标题】:"invalid database address" for PostgreSQL in JDBCJDBC 中 PostgreSQL 的“无效数据库地址”
【发布时间】:2015-01-01 07:15:33
【问题描述】:

我使用 PostgreSQL 创建我的数据库并将我的用户列表保存到其中,当我尝试通过 java jdbc 连接数据库时,我收到错误消息:

"java.sql.SQLException: 无效的数据库地址: jdbc:postgresql://localhost:5432/users"。

我使用 PostgreSQL 网站上的“JDBC41 Postgresql 驱动程序,版本 9.3-1102”。 这是我的代码:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class javaconnect {

private static Connection c = null;

public static Connection connectDb() {

    try {
        Class.forName("org.postgresql.Driver");
        c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/users", "postgres", "12345");
        return c;
    } catch (ClassNotFoundException | SQLException e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
        System.exit(0);
        return null;
    }

}
}

谢谢。

【问题讨论】:

    标签: java postgresql jdbc


    【解决方案1】:

    作为错误,

    "java.sql.SQLException: 无效的数据库地址:

    说您的数据库名称不正确。如果您安装了sql developer 之类的东西,请检查数据库名称。

    应在"jdbc:postgresql://localhost:5432/users" 之后在/localhost:5432/ 之后指定有效的数据库名称

    使用 jdbc 读取 JDBC using postgresql 以连接到 PostgreSQL 数据库

    【讨论】:

    • 谢谢,我用的是表名而不是数据库名:D
    猜你喜欢
    • 1970-01-01
    • 2013-10-13
    • 2017-05-06
    • 2013-02-19
    • 2013-01-02
    • 1970-01-01
    • 2020-11-05
    • 2017-03-07
    • 2014-02-21
    相关资源
    最近更新 更多