【发布时间】: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