'Connecting to remote postgres database using Java in Android Studio

This is my first time connecting to remote database using android studio. Program logs : not-Connected. I have used same function to connect in eclipse, but it doesn't work in AS.

static Connection connection = null;

public static void databaseConnect() {
        String jdbcURL = "jdbc:postgresql://ec2-52********amazonaws.com:5432/d3****hg";
        String username = "ve*****cgo";
        String password = "efc**********f16";

        try {
            connection = DriverManager.getConnection(jdbcURL, username, password);
            Log.d("log", "databaseConnect: Connected");

        } catch (Exception e) {
            Log.d("log", "databaseConnect: not-Connected");
            e.printStackTrace();
        }
    }

I have tried adding mssql-jdbc.jar to libs folder and adding android.premission.INTERNET to manifest, but I am obviously missing some steps. I couldn't find solution online so I am posting this question so somebody can hopefully help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source