Setting your own spring boot server via JDBC part 1

Michael Tong
Dec 31, 2020 · 6 min read
Image for post
Image for post
Photo by Markus Spiske on Unsplash

Have you ever figure out an idea for your own project and you finished building your UI but you just don’t know how to start up your own backend server?

Reading this article I assume you have mastered basics of core java before moving forward.

I will talk about how to get a spring jdbc project running on a pc. And this article will be talking about how to install all the required components onto your machine.

Image for post
Image for post
Photo by Tobias Fischer on Unsplash

Before getting the project setup, let’s understand what jdbc is.

It stands for Java Database connectivity, which is a Java API used to establish connection between the java language and different variety of databases, such as mysql, postgres,etc.

With spring boot, we can establish a running server that takes in request from client code, performing crud operations to update our database and getting those data back to the client.

To start off, let’s list out all the steps we need to take to get this project setup:

  • downloading intellij ide
  • setup project
  • set up libraries and configuration settings
  • set up database from scratch
  • setting up directories for the server code
Image for post
Image for post
Photo by Jukan Tateisi on Unsplash

Step 1: Download intellij

Go to Download IntelliJ IDEA: The Capable & Ergonomic Java IDE by JetBrains and download the community exe if you are on a pc. They also have versions for mac as well. If you are willing to pay, you can get intellij ultimate as well.

Step 2: Download Java

Go to Java SE — Downloads | Oracle Technology Network | Oracle and download a java package. Click on “JDK download” and it will download an exe file. Follow the steps properly and it will install the java library onto your machine. It can be any version but I personally use Java 8 since it’s all we need to support a simple jdbc project.

Image for post
Image for post

Step 3: Install postgres onto your machine.

Image for post
Image for post

Technically, you can use any relational database to complete this part. In my case I use postgres as the database to connect to. Go to PostgreSQL: Downloads and you can download the postgres database down.

If this step might not be clear, read this tutorial to install postgres with further clarification: Install PostgreSQL (postgresqltutorial.com).

P.S: set password as “password” just to be consist with the rest of the article.

Step 4: install pgAdmin

Image for post
Image for post

In this step, you will be downloading a UI application that will help you manage your database. I personally use pgAdmin but you are feel free to use anything else if you want to.

Once you install it, open the application on your pc and it should prompt you for your password. Once you login successfully, you should be able to see your database:

Image for post
Image for post

For now, we are not going to do much but eventually we need to use pgAdmin to validate the

Step 5: Go to spring initializer io and set up your spring boot project.

Technically, you can set it up on your own once you finish setting up intellij but spring initializer help us import a lot of the files & settings automatically.

Go to Spring Initializr and you should be able to see this page:

Image for post
Image for post

Now Chose maven project as your project option. Choose “Java” as your language option. You can choose any spring boot version but I just kept the same version as default.

Afterward, you can set project metadata, which contains description details of your project. You can leave it as it is or you can modify according to the functionality of your application.

Now set the packaging to a jar file and set java version to java 8. You can choose any java version you want but make sure the version matches the java library you installed onto this machine.

Click on “Add Dependencies” and in the search bar type in “PostgresSQL Driver” and then press enter.

Afterward, click on “Add Dependencies” and in the search bar type in “Spring Data JDBC” and select it.

Now click “generate” and it will generate a zip file. You can decompress it and it will be a folder consist of the project itself. For convenience, you can locate this folder under the C drive or D drive. Just create a project folder and put the project into the folder.

Step 6: Open intellij and set up additional dependencies in the pom.xml

Open intellij idea in your computer and it should prompt you to create a new project or open one. Click “open” and locate the folder of your project. Afterward, your project should look like this:

Image for post
Image for post

Now let’s set up additional dependencies in your pom.xml file.

Yes, I know. We should have included all the needed dependencies on step 3 but this is to ensure the project runs properly by containing all the important packages. Now locate your pom.xml and ensure it looks something similar to the file provided below:

r

Here, we have spring boot starter jdbc, spring boot starter web and spring boot starter as dependencies. All of these are important configuration settings for establishing a maven based spring boot jdbc project.

Of course, we also got the postgres dependency, which tells spring boot what kind of database we will be using.

Notice there is another package call lombok. This package is optional and is a java library that allows you to skip the step of writing getters and setters later on when you are setting up the entity object that we will map our database data to.

Step 7: Setup you database settings in your application.properties file

Image for post
Image for post

Locate the application.properties file under the resources path and place with the following contents:

If you installed postgres on the database, the postgres will always set to port 5432 by default. For our username it will default as postgres and the password will be “password”, which is set when you install postgres onto your machine.

Now you can go to DemoApplication.java under src/main/java/com.example/demo and click on the green play icon on line 9:

Image for post
Image for post

and your application should run on port 8080!

That’s it for the first part of this tutorial. I will cover the crud operations and what we need to know to fully set up this project.

For the second part, click on this link to finish the full tutorial: Setting your own spring boot server via JDBC part 2 | by Michael Tong | Jan, 2021 | Medium

Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Sign up for Best Stories

By Dev Genius

The best stories sent monthly to your email. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Michael Tong

Written by

Coding is nothing but a renovation of ideas through fundamental concepts. Stay sharp and stay hungry to learn!

Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Michael Tong

Written by

Coding is nothing but a renovation of ideas through fundamental concepts. Stay sharp and stay hungry to learn!

Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store