jdbc postgres url code example

Example 1: database url postgres

DATABASE_URL = "postgres://YourUserName:YourPassword@localHost:5432/YourDatabaseName";

Example 2: postgres jdbc

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

public class PostgreSQLJDBC {
   public static void main(String args[]) {
      Connection c = null;
      try {
         Class.forName("org.postgresql.Driver");
         c = DriverManager
            .getConnection("jdbc:postgresql://localhost:5432/testdb",
            "postgres", "123");
      } catch (Exception e) {
         e.printStackTrace();
         System.err.println(e.getClass().getName()+": "+e.getMessage());
         System.exit(0);
      }
      System.out.println("Opened database successfully");
   }
}

Example 3: postgresql database url

PG_URI=postgres://postgres:root@localhost:5432/campus

Tags:

Sql Example