Spring Boot + Apache Kafka Tutorial - #21 - Configure MySQL Database


Welcome to Spring Boot + Apache Kafka Tutorial series. In this lecture, we will configure the MySQL database in our Spring Boot project.

Lecture - #21 - Configure MySQL Database

Transcript:

Hi. Welcome back. In press lecture we have implemented to capture consumer to consume the data from the capture topic. Next, we need to store that data into the database. Right. For that in this lecture will configure magical database in that Springwood project so that our Springwood application can able to connect to the magical database. Right. So let's head over to that idea and let's go to grab the consumer database project and go to Resources folder. Within this quarter we have application DOT properties, right? So within this application DOT Properties file, we're going to configure my single digits. Well, before that, first we need to create a database. So let's go to my cycle workbench and here just type the yes go statement database followed by database name, let's say Wikimedia. So we commit is going to be our database name. Let's fire this as go statement and replace the schemas. And there we go. Wikimedia database is created. So once we create a database next we need to add the required dependencies and it has been good project. So basically we need to add spring date as a dependency as well as my psychologically we should do it. So in order to get these dependencies, what we can do is we can go to the Stoddard Spring Godiva website that is planning to close our website and go to that add dependency section all year and just type spring. JP So you will get this option like Springer, that your base will go ahead and choose this spring at AGP next we use my second year, whichever, right? So just tap on article. You will get to my second day. All here, just choose it. Now we have these two dependencies. Okay? So whenever you want to connect to us, bring your application to my cycle database, then you have to add these two dependencies. All right. So is being that AGP by default it uses I want it as a GP it and we use AGP to simplify the reportedly error down here. Okay. And we use my cycle driver to connect always being with application to that database. The database is in my database. So I go to the explore here option and go to politics email and just go ahead and grab these two dependencies. Okay? Just copy these to dependencies and go to English idea and go to politics, envelop, capture, dot capture, open consumer open database project. Okay, so make sure that you are in the right project. So go here in a prominent example and create a dependency section and just paste these two dependencies. Perfect and click on this law moment changes like when will you know we have added required dependencies? Okay, now let's go to application dot property file and let's configure my single database. Okay, so let me go to resources folder. Within our resources quarter, we have application properties. Well and within this application that property file where I want to computer my cycle, it is to just type the property spring dot data source dot USD local to C. So we are going to configure databases, whatever, connect to the magical database, right. So JD, we see Colon, my mascot and then localhost real, we are connecting our Springwood application with the local magical database, hence localhost followed by the port of domestic server that is 3306 followed by database name, that is Rikki Media. And then let's configure database username and password just type the property springboard data source dot user name a call go route. Well, in my case, I have given a database user name as a root, but make sure that whatever the database user name that you how you have it. When we have a convention, we're here. So similarly, let's consider database password spring dot data source dot password your call to my head. Date one, two, three. Well, whatever the database password you have given to your database, make sure that you have to go here. After that, we need to configure a couple of hibernate properties. Well, let's first configure hibernate delete. So just tap the update. Spring dot GPA, dot properties, dot hibernate dot let it call to work that hibernate that delayed lot my cycle eight deleted so make sure that you just little did it too magical it is done it is diluted as of now so this. It is required. I have a need because I want it to be reported delayed to create this go statement to the respective database window. In this case, my cycle is there that good database window, right. So based on this date it I want it will basically clear days group statements. Next let's configure one more hibernate property automatically create the database table. Let's bring JP hibernate dot ddl happen I do a call to update the this will create you know database developed domestically. Well we want to also see that happening generally as close statement in a country right for that let's consider put more hibernate properties or here that is spring or Jupiter properties don't hibernate talk show and display as critical to do so this will basically show this go statement that is generated by hibernate in a console and this spring or greater properties that hibernate dot use underscore is going to square comment so this property will basically print the comment next spring logic better properties that hibernate dot permit and this way as critical to do so, this property will basically tells hibernate that whatever this growth statement that will bring in accounts which would be well formatted. All right so these are the few, you know, properties that we have to configure in order to connect our springboard application or my cycle database. Now let's run this promote application and let's verify whether I was remote application will able to connect to domestic database or not so go to mean in different class. So make sure that you are in a right project. So open this capture consumer database project and go to many different class of this project that is Springwood Consumer Application and run this class. And you can see there is a no errors in a console. It means we have successfully completed my cycle database in the Springwood project. Okay, great. Your next lecture will appear to say the data into the My Cycle database. Alright, I will see you in the next lecture.

Free Spring Boot Tutorial | Full In-depth Course | Learn Spring Boot in 10 Hours


Watch this course on YouTube at Spring Boot Tutorial | Fee 10 Hours Full Course

Comments