Problems connecting Postgres with java [duplicate]

0

Well, I'm having a problem connecting to my java application with my database (I'm using pgAdmin4 which basically is postgres).

Java code:

public class ConnectionFactory {

private static final String DRIVER = "org.postgressql.Driver";
private static final String URL = "jdbc:postgresql://localhost:5432/NomedoDB";
private static final String USER = "postgres";
private static final String PASS = "";

public static Connection getConnection() throws SQLException {
    try {
        Class.forName(DRIVER);

        return DriverManager.getConnection(URL, USER, PASS);
    } catch (ClassNotFoundException ex) {
        throw new RuntimeException("Erro na conexão", ex);
    }
}
}

Main:

public static void main(String[] args) throws SQLException {
    // TODO code application logic here
    ConnectionFactory conn = new ConnectionFactory();
    conn.getConnection();
}

Error:

  

Exception in thread "main" java.lang.RuntimeException: Connection error       at ConnectionFactory.getConnection (ConnectionFactory.java:22)       at BDLearning.main (BDLearning.java:22)   Caused by: java.lang.ClassNotFoundException: org.postgressql.Driver       at java.net.URLClassLoader.findClass (URLClassLoader.java:381)       at java.lang.ClassLoader.loadClass (ClassLoader.java:424)       at sun.misc.Launcher $ AppClassLoader.loadClass (Launcher.java:335)       at java.lang.ClassLoader.loadClass (ClassLoader.java:357)       at java.lang.Class.forName0 (Native Method)       at java.lang.Class.forName (Class.java:264)       at ConnectionFactory.getConnection (ConnectionFactory.java:18)       ... 1 more

I've seen in some places that could be the driver for postgres, but I've tried with several and it still did not work, I'm currently using here that were downloaded at link

    
asked by anonymous 06.10.2017 / 23:52

1 answer

0

It took me a while to realize your error, it's a simple typing issue because the correct driver name is Class.forName("org.postgresql.Driver") you've put 2's.

    
07.10.2017 / 14:26