【发布时间】:2015-06-21 11:29:23
【问题描述】:
我正在运行 Netbeans 8.0.2。我正在学习 JDBC,并希望将其连接到 PostgreSQL 数据库。我查找了所有可能的答案,但没有答案使它起作用。
我还在左侧菜单中选择了库为PostgreSQL JDBC Driver -postgresql-9.2-1002.jdbc4.jar
显示的错误是:
发生 SQL 异常java.sql.SQLException: 找不到合适的驱动程序 对于 Jdbc:postgresql://localhost:5432/postgres
代码如下:
try {
Class.forName("org.postgresql.Driver");
}
catch(ClassNotFoundException e) {
System.out.println("Class not found "+ e);
}
try {
Connection con = DriverManager.getConnection
("Jdbc:postgresql://localhost:5432/postgres","postgres",
"gautam");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery
("SELECT * FROM role");
System.out.println("id name");
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("name");
System.out.println(id+" "+name);
}
}
catch(SQLException e){
System.out.println("SQL exception occured" + e);
}
【问题讨论】:
-
我想知道
jdbc:是否区分大小写。 (我猜这不是问题,但试试吧……)
标签: java postgresql netbeans jdbc