How to Install and Connect Heroku PostgreSQL in Android
Hi Guys, as you already know while developing a web application or connecting our database to our project on an android phone. You’ll get confused that how you will connect your application to the database to test the application. However, after many tries, you’ll get disappointed and drop the project in the between while development stage. but don’t worry here, we going to tell you that how you can connect your application to your project.
Today we will be talking about this topic and will solve all the problems related to web applications. For developers, whoever develops Applications on their Android phone. This will work on every framework it may be a Flask or any other framework it will work on each and every situation.
What You need?
- An Android Phone
- Working Internet
- Termux App (from Playstore)
- A Heroku account
1. Create Heroku PostgreSQL Database
Lets, start our journey by creating an account on Heroku which is a free cloud computing-based web host which supports almost every language application. You can check out their premium plans also If you like to use them.
First of all, You need Heroku Account If you don’t have it you can create one by going to this website: www.heroku.com. After, landing on this page Sign up for Free then create a new app by clicking Create new app button.
After that, Go to the Resources option of your Heroku App and Click on Find more add-ons. It will open you a new tab where you have to find Heroku PostgreSQL and add it to your created app.
As the Heroku PostgreSQL add-on added Click on it. That will again open you a new tab where you can see the Credentials and URI of your Database in the Setting tab then the View Credentials button. which you can use to connect your Web app.
That’s it, we have to do from here and don’t share your URI with anybody this can cause a bad impact on your application or someone can get full access to your database.
2. Setup Heroku PostgreSQL
Let’s move on to our 2nd process. To use Heroku PostgreSQL on Android, we have to install the PostgreSQL package.
Open your Termux App which acts as the terminal in our Linux-based phone. If you don’t have updated your existing packages you can do it by running the command:
apt update && apt upgrade -y
If you don’t have GIT Package installed then Install it by running the command:
pkg install git -y
Now, Let’s start now install Heroku PostgreSQL in Termux. To install simply run this command:
pkg install postgresql -y
It will be installed on your device in a few minutes. That’s it, Now we can use normal MySQL syntax to creating or showing our Database tables.
To connect your Heroku PostgreSQL database with the installed package on Termux. Do run:
Now, you will be logged in to your Heroku PostgreSQL Database with Termux. Do \dt to show tables if any presents. You can now create your new table by using it.
To show the tables in your Database you can simply type this command:
If there are any tables preset in your Heroku PostgreSQL Database it will show. Either you can create a test example of tables using this command:
Create table test( S.No SERIAL PRIMARY KEY, Name TEXT(30) UNIQUE, Roll INTEGER(20) NOT NULL UNIQUE, Date TIMESTAMP NOT NULL UNIQUE);
This will create a test table inside your Database to check that you can use \dt to show tables but To show the contents inside the table you can use:
Now, after creating the database you can use your URI anywhere you want like Flask or any web app which uses database.
If you want to host your web application on Heroku comment write below. we will create another tutorial for that.