I am running Netbeans 8.0.2. I was learning about JDBC and wanted to connect it to a PostgreSQL database. I looked up for all possible answers but no answer made it work.
I have also chosen the library on the left side menu as PostgreSQL JDBC Driver -postgresql-9.2-1002.jdbc4.jar
The error shown is:
SQL exception occuredjava.sql.SQLException: No suitable driver found for Jdbc:postgresql://localhost:5432/postgres
Here's the code:
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:
is case sensitive. (I'm guessing it's not the problem, but try it...) – user253751