JDBC中的PostgreSQL的"无效数据库地址"

Foa*_*ebi 4 java postgresql jdbc

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

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

我使用PostgreSQL网站上的"JDBC41 Postgresql Driver,Version 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;
    }

}
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

San*_*ish 5

由于错误,

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

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

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

使用postgresql读取JDBCPostgreSQL使用jdbc 连接到数据库