Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    public static void main(String[] args) throws Exception {
        String hostname = "", dbname = "", username = "", password = "";
        Class.forName("org.postgresql.Driver");
        Connection connection = DriverManager.getConnection("jdbc:postgresql://" + hostname + "/" + dbname,
                username, password);
        ResultSet rs = connection.createStatement().executeQuery("select version() as version");
        while (rs.next()) {
            System.out.println(rs.getString("version"));
        }
    }
}