Table of contents
1.
Introduction
2.
What is PostgreSQL?
2.1.
Why should we use PostgreSQL?
3.
Installing PostgreSQL on Windows
4.
Adding PostgreSQL to New Vaadin Applications
5.
Adding PostgreSQL to an Existing Vaadin Project
6.
Frequently Asked Questions
6.1.
What is a Relational Database Management System?
6.2.
Does Relational Database Management System provide an interface between the users and the application?
6.3.
How is PostgreSQL different from MongoDB?
6.4.
How is PostgreSQL different from MySQL?
7.
Conclusion
Last Updated: Mar 27, 2024
Easy

Connecting to PostgreSQL

Author Adithi Mahesh
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Hello there!

Welcome to another article about PostgreSQL. You will learn everything about connecting PostgreSQL to your Vaadin applications.

Hello

 First, let's understand what Vaadin is and why we need PostgreSQL for it. Vaadin is a multi-platform open source platform where you can develop applications for mobile and web without having to code in HTML and javascript. Exciting right? But for the question of which language it understands, it's Java. You'll have to code in Java to get your applications working.

But don't worry too much; they have UI components as sets of codes; you can use them and alter them as you wish. So customize them and use them to develop a beautiful yet functioning website or mobile application for your target audience.

Check out Introduction to VaadinGWT vs. VaadinVaadin ToolsVaadin componentsVaadin Configuration, and many more!

 

What is PostgreSQL?

Before jumping into how you can connect PostgreSQL to Vaadin applications, let's understand what PostgreSQL really is. 

Database

 

PostgreSQL is a successor of the Ingres database management system. It is a relational database management system that is free and open source. PostgreSQL is also known as Postgre. 

Actually, PostgreSQL was designed firsthand for MacOS. Still, since most applications and websites work on all platforms, it was launched for Windows and Linux.

Do note that PostgreSQL is an RDBMS model that follows the ACID properties. ACID stands for:

  • Atomicity means that every function of an element in the database is treated as one single piece and solved separately rather than randomly combining everything.
  • Consistency means that each function applied to the database element is consistent and does not break in between or have any error.
  • Durability means that the transactions, whether completed or not, will try as much as possible to achieve them. Still, if it doesn't work out, it will be terminated.
  • Isolation means that the processes on different elements in the database are kept separate and will not mix up with each other.

Learn PostgreSQLPostgreSQL Create DatabasePostgreSQL Database, and many more!

Why should we use PostgreSQL?

As told above, PostgreSQL is a Relational DataBase System. So, once a trigger is set on the tuple or block of data. Then the trigger gets applied when new data is entered into the database. 

Why should we use PostgreSQL

 

So by using PostgreSQL, you will be able to achieve all those things, and since it's open source and free of cost, you can use it for your projects and practices.

It is mainly designed for handling vast amounts of data from single machines to massive data warehouses with many target users.

 

 

Installing PostgreSQL on Windows

Now that we know about PostgreSQL and why we need to use it, let's look at how we can install it in your system to use it practically.

Windows

 

  1. Go to https://www.postgresql.org/download/ 
Go to https://www.postgresql.org/download/


2. Select Windows.

selecting windows

3. Choose Interactive Installer by EnterpriseDB as Graphics Installer by BigSQL is outdated.

4. Choose the version you want and the Windows operating system environment, and click on download.

5. Wait for it to download.

6. Once downloaded, open the downloaded file .exe format.

Once downloaded, open the downloaded file .exe format.

7. Once you see the welcome screen, you can click "Next."

8. Set the location where you want to store the installation directory and click "Next."

Set the location where you want to store the installation directory and click "Next."

9. A list of components appears on the next screen, make the choices and click on "Next."

A list of components appears on the next screen, make the choices and click on "Next."

10. Choose where you want to store the data files on your computer and click "Next."

Choose where you want to store the data files on your computer and click "Next."

11. Create a password and click "Next."

Create a password and click "Next."

12. The port number is the default, so you can leave it as it is and click "Next."

The port number is the default, so you can leave it as it is and click "Next."

13. The pre-installation is displayed on the screen; check it once before clicking next.

The pre-installation is displayed on the screen; check it once before clicking next.

14. A new window will appear. Click "Next."

A new window will appear. Click "Next."

15. Stack builder is checked on default; uncheck it and click "Finish."

Stack builder is checked on default; uncheck it and click "Finish."

16. Open start and search for pgAdmin4. This will launch PostgreSQL.

17. On the home page of pgAdmin, you will have to search for PostgreSQL 10 on the left column and open it.

18. Enter the earlier set password and click on OK.

Password entering

19. The installation is successful only when you can see the dashboard on the screen. 

installation
Dashboard

Installing PostgreSQL in MacOS is the same as installing it in Windows.

Adding PostgreSQL to New Vaadin Applications

Now that you have installed PostgreSQL into your system, let's see how you can use it in your Vaadin applications.

Adding PostgreSQL to Vaadin

 

  1. Open Vaadin.
  2. In Vaadin Start, go to the SETTINGS tab.
  3. There you will have to select "Technology."
  4. A new section will drop down where you can see the database on the 4th line. There you will have to select "PostgreSQL" in the dropdown.

Doing this creates a dependent file with the extension pom.xml, which is present in the project you have generated. All necessary configurations to connect to PostgreSQL are contained in the generated project.

<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
</dependency>

This is what the dependency looks like in the pom.xml file by the generated project.

Since PostgreSQL uses Spring Datasource, you will see it on the configuration of PostgreSQL.  

Application.properties is generated once the project is generated; it looks like something given below.

# PostgreSQL configuration.
spring.datasource.url = jdbc:postgresql://localhost:5432/postgres
spring.datasource.username = postgres
spring.datasource.password = password
spring.jpa.hibernate.ddl-auto = update

The values given in this configuration are default. While installing PostgreSQL in your system, you would have set specific values for these configurations. Check if the values are the ones you have given during the installation.

When you begin the application, In your IDE's console, you should see something like this:

Database available at 'jdbc:postgresql://localhost:5432/postgres'

Adding PostgreSQL to an Existing Vaadin Project

You can add PostgreSQL to an existing Vaadin project by:

 ~ adding the pom.xml dependency file and application.properties configuration file to the project.

Adding to an existing project

 

Frequently Asked Questions

What is a Relational Database Management System?

A relational database management system maintains a relationship between the data stored in the database. It also manages data and retrieves it whenever required. It also helps in querying the database.

Does Relational Database Management System provide an interface between the users and the application?

Yes, RDBMS provides an interface between the users and the application.

How is PostgreSQL different from MongoDB?

MongoDB is a document-based database, and it cant be compared to a relational database management system like PostgreSQL.

How is PostgreSQL different from MySQL?

PostgreSQL is the way to go if you have complex data and need an extensive database with many functions. MySQL is for smaller databases and for practice projects and mini-projects.

Conclusion

I am concluding this article by saying that I'm grateful you have read this entire article with utmost interest and dedication. I hope it met all that you were looking for and expect that you have installed PostgreSQL and are using it for your Vaadin projects.

You can also check out our materials related to this article, SQL vs. Non-SQL DatabasesNormalisationFundamentals of Data SystemsPostgreSQL vs. MySQLAWS DatabaseSkills for becoming a Data ScientistArtificial Intelligence EngineerSystem Design StrategiesKaggle, and many more!

 

Live masterclass