Java Utililty Methods JDBC PostgreSQL Connection

List of utility methods to do JDBC PostgreSQL Connection

Description

The list of methods to do JDBC PostgreSQL Connection are organized into topic(s).

Method

voidClearDatabase()
Clear Database
String ConnectionString;
Connection PostgreSQLConnection;
Statement stmt;
ConnectionString = "jdbc:postgresql://127.0.0.1:5432/abia/";
try {
    Class.forName("org.postgresql.Driver");
} catch (Exception e) {
    System.out.println(e);
...
ConnectioncreateConnection()
create Connection
return DriverManager.getConnection(DB_CONNECTION_URL, DB_USERNAME, DB_PASSWORD);
ConnectiongetConnection()
get Connection
String url = "jdbc:postgresql://localhost/marketplace";
Properties props = new Properties();
props.setProperty("user", "marketplace");
props.setProperty("password", "test");
return DriverManager.getConnection(url, props);
ConnectiongetConnection()
get Connection
Connection con = null;
try {
    Class.forName("org.postgresql.Driver");
    con = DriverManager.getConnection(DB_URL, USERNAME, PASSWORD);
} catch (ClassNotFoundException | SQLException ex) {
    System.out.println(ex.getMessage());
return con;
...
LinkedListgetDataFromTable(String tableName, String[] columns)
get Data From Table
Connection conn = getConnection();
LinkedList<String> list = new LinkedList<String>();
try {
    Statement st = conn.createStatement();
    String sb = "select * from " + tableName;
    ResultSet rs = st.executeQuery(sb);
    while (rs.next()) {
        StringBuilder sql = new StringBuilder();
...
ConnectiongetDBConnection()
get DB Connection
if (connection == null)
    connection = connectToDatabase();
return connection;
ListgetListDatabaseFromMaster()
get List Database From Master
List<String> lista = new ArrayList<>();
Connection connection;
try {
    Class.forName(driver);
    connection = (Connection) DriverManager.getConnection(url, user, senha);
    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery("SELECT name FROM public.system_database;");
    while (resultSet.next()) {
...
ConnectiongetPostgresConnection()
get Postgres Connection
String url = "jdbc:postgresql://192.168.231.10:5432/flexims";
Properties props = new Properties();
props.setProperty("user", "flexims");
props.setProperty("password", "123456");
return DriverManager.getConnection(url, props);
ConnectiongetPostgresConnection()
get Postgres Connection
Class.forName("org.postgresql.Driver");
Connection connection = null;
try {
    connection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/jira", "postgres",
            "Jira733");
} catch (SQLException e) {
    System.out.println("Connection Failed! Check output console");
    e.printStackTrace();
...
ConnectiongetPostgresJDBCConnection(String host, int port, String nameDB, String userDB, String passwordDB)
get Postgres JDBC Connection
try {
    Class.forName("org.postgresql.Driver");
    Connection con = null;
    con = DriverManager.getConnection("jdbc:postgresql://" + host + ":" + port + "/" + nameDB, userDB,
            passwordDB);
    return con;
} catch (Exception e) {
    throw e;
...