hey guys welcome back
in this video we're going to see
how we can connect a springboard
application with postgres SQL database
right so if you have any doubt on how to
install the postgres SQL in your mission
you can refer to my previous video I'll
give you the link in the description and
also uh as a label okay so let's jump
into the video
let's start by going into spring
initializer I'm going to create a maven
project in Java
[Music]
that's what I'm going to use Java 8.
that dependencies I'm going to use web
so the normal dependencies what that
we'll use tools
I'm going to use rest
Repository
[Music]
what else you need uh I don't think I'm
going to get the main one is GPA that's
what we're going to use we are not going
to use jdbc template we are going to use
jspa
um I'll use Slumber for Generation the
boilerplate code generation
which driver okay I think that's all we
need let's click on generate so it will
generate the project for us
that we got we'll go to the folder
let me extract it
is
extracted
let me go to IntelliJ and import the
projector
foreign
[Music]
let's start the application now let's
see what happens
trying to start the application
[Music]
yeah it's failed uh it is searching for
the data source URL uh so that's where
it's failing so let's keep those details
because we have the postcode SQL refined
in our dependency so if you look at here
we have a post Craigslist SQL the jpa we
have to provide the data database
reference so the JPI is referring to the
data source URL that does not exist in
the resource let me go to the properties
and add few properties here which is
spring
the URL you can find it from our
admin you can just go to First cable
right click properties
and you can click on connection and you
can see it's on localhost
5432
right so let's take it from there
um
you're just going to see jdbc it's a
jdbc connection
and we are connecting it to post scratch
or screen skill
and the URL is going to be local
host
and five four three two that's the port
right and then we are going to use the
database which is here is YT demo that's
going to be very useful
right and we are we have the data source
so with this let's see let's let's start
the application so uh
let's restart the application again
[Music]
there you go the application is started
right it's able to connect to the
database and get all the details so I uh
JP is internally using hibernate to
connect the screen like here in
springboard so let's give some more
details like
um the dialect that it needs to use it
[Music]
but like the spring boot uses hibernate
for jpa implementation so that's why we
are providing the uh postgrades SQL
dialect
create so let's say if you want to
create anything create a table or
complete anything so we it will all work
in the way of postgres SQL
through JPM
so that's why we're giving this dialect
that's where it is and let's go and um
create the entities
so if you want to give more details
there are
like you can
provide I will need to show the details
or whatever it may be in the console you
can stop that and also you can update
the database
I mean like you can you can do a create
or update the database whenever the
server is restarted so all those stuff
you can do here so let me add that
property also
so far and let's go ahead and create a
new
model object
before and let's say let me create one
for
person
it's going to be a normal one right
create this
and I'll add it to a package called
Model so it should be
inside
temperature
as data
that way you don't need to give any
[Music]
Getters and Setters right and also this
is and this is going to be an entity for
us
jpa
and I'll also give the table name
and the table name is going to be
person
that's all it is and I'm going to create
a ID name
that's that's all I'm going to do now
create private
and
[Music]
long
ID
drive it
string name
so the two Fields I'm gonna create let
me go here and I just want to treat this
as an ID
there we go we created an object
entity we created an entity and we've
created an uh
created two uh members which is ID and
name this is going to be the columns one
is the ID which is the primary key for
this person let me go ahead and create
one more package which is Repository
foreign
let me add new
channel so it's going to be an interface
create an interface
it's going to be
Arsen repo
going to
extend this with jpa
I'm going to annotate this as
restroom
rest resource
and there you go that's all we need so
let me restart the application
[Music]
the start of the application let's go
ahead and hit this URL
localhost 8080 slash
person
I have this
to see what we have
here we have this URL
person
s
we see if you look at here the persons
is empty
so let's let's add some values to the
data database through our risk
controller let's create one risk
controller
you can add value for us
person raised person controller
[Music]
and we are going to use this as a
rest controller
will Define a
post mapping sorry
[Music]
[Music]
the name of course
we hit it from here
so by now it should have created uh
table here
very true
[Music]
because we
[Music]
start the server if the table does not
exist it will create
sell it
[Music]
foreign
[Music]
so let me go ahead here
and
head
add person
it's going to be post mapping and the
body is going to be
it's going to be
name
it's going to say and boom and
write this send it again
there you go it could add it
let me go to database and just query
this
[Music]
there you go we got the value updated
and if you want to get the value back
right so we already have the rest
repository configured so we just go here
and hit the URL just refresh the page so
you can see here there is a record in
this person
you can get through this person you in
this even through this URL let's give
slash zero
and you get there
get the complete object for that that's
why we are using the risk repository
here right so even like this way you can
do uh update delete you can create your
own methods and do it right
that's all uh
that's all we have for um
connecting springboard application with
a postgres SQL we'll see you in the next
video thanks for watching
[Music]