Java Discussion Forums

There's no such thing as a stupid question. Ask. Discuss. Learn.

Java connection with postgres DB by jdbc (Intellij IDE )

Hi All !
I use intellij Idea to code Java
I use JDBC to connect to the postgres database. but I have an exception
(** I downloaded JDBC Driver for Postgres** )

This is code source
Image
This is exception
Image

Trưởng Nguyễn 5 months ago
  • Trưởng Nguyễn

    import java.sql.Connection;
    import java.sql.DriverManager;

    public class dbConnection {
    public static void main(String args[]) {
    Connection c = null;
    try {
    Class.forName("org.postgresql.Driver");
    c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/StudentManagement",
    "postgres", "123456");

        } catch (Exception e) {
    e.printStackTrace();
    System.err.println(e.getClass().getName()+": "+e.getMessage());
    System.exit(0);
    }
    System.out.println("Opened database successfully");
    }

    }


  • Whitelisted Links