FULL COURSE: Spring MVC and Hibernate (200+ videos)
This Hibernate tutorial series will help you quickly get up to speed with Hibernate.
DOWNLOAD SOURCE CODE for Hibernate tutorial.
View more videos on the playlist, Hibernate Tutorial: https://goo.gl/UKAdaq
Follow luv2code for more Hibernate tutorials:
If you liked my Hibernate tutorial, then join my mailing list: Get exclusive access to new Java tutorials.
Questions or problems about this Hibernate tutorial? Post them in the comments section below.
Want to suggest a video for my Hibernate tutorial? Leave a comment below. I'm always looking for new video ideas.
Let me know what video you'd like for me to create for this Hibernate tutorial.
Hibernate Tutorial Transcript
In this video, I'm going to show you how to set up your Database Table. We have two scripts that we'll make use of, and these scripts were available in the source code download.
The first script is 01-create-user.sql. The second one is 02-student-tracker.sql I'll actually step through each one of these scripts just to show you what they're used for.
All right, let's start with the first script, 01-create-user.sql. Basically what it's going to do, it's going to create a new MySQL user for our application. The user ID will be hbstudent, and the password will be hbstudent. Our app will use this to communicate with the MySQL database.
Let's go ahead and swing over and look at the files here for a second. Here's the core source code. This is basically once you download it to your system, and you unzip it, then you'll have these directories here. What I'll do is I'll go ahead and look at the Hibernate demo directory, and inside of this directory is another sub-directory called SQL Scripts, and inside of the SQL Scripts there are the two files, 01-create-user and 02-student-tracker.sql.
What we'll do is we'll actually read these files in the MySQL Workbench tool, and actually execute them. Right now we're just looking at them on our raw file system.
Let me go ahead and pull up the MySQL Workbench. Let me log in as the root user right now. We enter our password. It's the same password that you used during installation.
Let's click on this folder icon, and let's open up that first file. I'll click on the folder icon, and it will take me to my file system. I'll go into that course source code directory that we looked at earlier. Hibernate demo, and SQL Scripts, and I'll choose the first file here, 01-create-user.sql. I'll click on the open button.
Here's the file. Again, basically all we're going to do is create a user called hbstudent, and they're going to have a password of hbstudent. Then this last line here basically grants all the privileges such that this user can go ahead and create tables, and do any other things they need to do with the database. I'll click on this little lightning bolt here, this yellow lighting bolt, to actually execute the code and perform the operation. This looks good. Down at the bottom, you should see the green check marks, meaning that both of those statements executed correctly.
At this point, we have a new user that was just created, hbstudent. What I'd like to is go ahead and close this root connection, and I'm going to create a new connection for this student just to verify that this student was created successfully, and also to verify that we can actually log in with that student. I'll create a new connection name here. I'll call it hbstudent. You can give any name of the connection, but for the user name, this is really important, you have to give hbstudent, just like we had in our script. What I'd like to do is click this little test connection button at the bottom. They'll prompt us with a password. Again it's the same. Hbstudent. Then click on okay. We should see the success. Yeah, good job.
That's successful, so we know that our user was created successfully, and we also know that we can log in with that password. Let's go ahead and click on okay here in the corner. Now, let's go ahead and double click this hbstudent connection, just so that we can connect to that database.
Great. We're in. This all looks good right now. This is a verification that yes, we created our user successfully, and we can log in with that user.
[snip] For complete transcript, Select More - Transcript
This is the end of the Hibernate tutorial transcript.