Java JDBC PostgreSQL Connection getDBConnection()

Here you can find the source of getDBConnection()

Description

get DB Connection

License

Open Source License

Declaration

static Connection getDBConnection() throws SQLException, ClassNotFoundException 

Method Source Code


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

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

public class Main {
    private static Connection connection = null;

    static Connection getDBConnection() throws SQLException, ClassNotFoundException {
        if (connection == null)
            connection = connectToDatabase();
        return connection;
    }//from   ww  w.j av  a 2  s .c o  m

    static Connection connectToDatabase() throws SQLException, ClassNotFoundException {
        Class.forName("org.postgresql.Driver");

        String url = "jdbc:postgresql://localhost/autoeval";
        Properties props = new Properties();
        props.setProperty("user", "dude");
        props.setProperty("password", "supersecret");
        // props.setProperty("ssl", "false");
        return DriverManager.getConnection(url, props);

    }
}

Related

  1. ClearDatabase()
  2. createConnection()
  3. getConnection()
  4. getConnection()
  5. getDataFromTable(String tableName, String[] columns)
  6. getListDatabaseFromMaster()
  7. getPostgresConnection()
  8. getPostgresConnection()
  9. getPostgresJDBCConnection(String host, int port, String nameDB, String userDB, String passwordDB)