Java JDBC PostgreSQL Connection getConnection()

Here you can find the source of getConnection()

Description

get Connection

License

Open Source License

Declaration

public static Connection getConnection() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static final String DB_URL = "jdbc:postgresql://localhost:5432/events";
    public static final String USERNAME = "postgres";
    public static final String PASSWORD = "rame";

    public static Connection getConnection() {
        Connection con = null;/*ww w . j a va2s  .  c  o m*/
        try {
            Class.forName("org.postgresql.Driver");
            con = DriverManager.getConnection(DB_URL, USERNAME, PASSWORD);
        } catch (ClassNotFoundException | SQLException ex) {
            System.out.println(ex.getMessage());
        }
        return con;
    }
}

Related

  1. ClearDatabase()
  2. createConnection()
  3. getConnection()
  4. getDataFromTable(String tableName, String[] columns)
  5. getDBConnection()
  6. getListDatabaseFromMaster()
  7. getPostgresConnection()