Java NetBeans Tutorial: Connecting to a MySQL Database with Java, JDBC and NetBeans

preview_player
Показать описание

In this video you will learn how to connect to MySQL with Java and NetBeans.

Please subscribe to this channel :-)

Video Transcript
Time - 00:00

Time - 00:10
Let's go over the development process. The first thing we'll do is review the database tables, then we'll download and add MySQL database driver to NetBeans, then we'll actually create the Java code.

Time - 00:25
Let's look at our database and see what data we have. We'll move to the MySQL workbench tool. See that we have a table called Employees and then we'll do a select star from that table and we'll see that we have three employees currently in our database.

Time - 00:46
Now I'll create a simple NetBeans project. I'll go to the File menu, I'll select new Project. Make sure the Java application is selected and click next. For the project name, I'll give it jdbcdemo, I'll click Finish. Now what I'll do is I'll add a new Java Class. I'll select the project, I'll right click, I'll select New Java Class. For the name of the class I'll enter demo and hit finish. Now I have a basic Java Class ready to go.

Time - 01:26

Time - 02:07

Time - 02:35
Now we need to copy this file to the NetBeans project directory. I'll right click, I'll select copy then I'll switch over to NetBeans, I'll click the files tab and I'll select my project and I'll right click and I'll say paste. Even though the file is copied over, we still need to tell NetBeans that this a JAR library that we'll use on our project. What I'll do know is I'll click on the projects tab, I'll go to libraries and I'll choose add library and now I'll navigate to that NetBeans project directory where I actually have the file stored. Jbdcdemo and MySQL connector Java bin and I'll select choose. Then I'll expand this library's folder and we'll see that now this MySQL Java driver is part of this NetBeans project.

Time - 03:37
Now let's start with the coding. The first thing I need to do is import Java to SQL package and then I'll drop in code for this main map it and then I'll walk through the code and show you how it works. This is our main map it, the main routine for the application. Then we have variables for the connection statement and result set. We also have the user id and password that we'll use.

Time - 04:03
Then the first step is getting a connection to a database. We'll use the URL, the user id and the password. Then we go through and we create a statement object. Then we use this statement object to execute SQL query, select star from employees, then we'll process the result set and we'll simply print out the last name of the employee along with the first name. We have our accession handler and then we also clean up our resources at the end once we're done.

Time - 04:42
Then to actually run the application, we will right click, select run file and at the bottom we have our output. We have our three employees that were listed in the database and our Java program was able to access it successfully. Great.

Time - 04:59
Рекомендации по теме
Комментарии
Автор

Bro never delete this video pls. BTW THANK YOU SO MUCH!

WhoamiOfficial
Автор

Thanks bro, 3 years later this video help me too much ! I appreciate it

VictorSilva-iuvx
Автор

Thank you for this great tutorial!
Now i am able to connect the Java with MySQL :)
Thanks again!

Ammarali
Автор

Thanks, you'r way to explain is very simple and to the point. It's easy to follow and I don't fill I'm wasting my time. You'r code works great! I use you'r example code but with "try with resources" so you don't need code to close the data base, Java will do it for u. Thanks again.

peraruor
Автор

One of the Best online YouTube  teachers! Thanks for the video.

josiahtobas
Автор

Chad, thank you very much for this wonderful and easy to follow tutorial.... Keep on sharing...

cs
Автор

some helpful work you done HERE>>

omkarrekulwar
Автор

Thank you very much, it was exactly what I was looking for to solve a problem with connection to a firebird database. I think that this tuto will be useful at least beginners.

caribooland
Автор

finally it's work... i have been trying this for a long time so thank you for this great video :)

yasirn.romaya
Автор

thank you.. this is what i was looking for.

nicholasn.sulaksana
Автор

thank u so much bro...netbeans connect ho gya mysql se

muhammadsalman-sgdr
Автор

Many thanks! Your video helped solve my problem.

Danil-
Автор

Thank you, Pedro Gomes - São Paulo - Brasil

pedrogomessantos
Автор

Hi thank you for you tutorials.I have question, Between Netbeans and Eclipse which is mostly preferred to develop swing application.

iann
Автор

Amazing tutorial. sorry for my bad english i'm from Italy

Sebastian-devb
Автор

This was very helpful for me. Thank you so much!

mikro
Автор

that's mysql_connector was missing all the time for me
thx u SIR

djdan
Автор

another thing is the 3306/demo, where does the demo come from, can i write demo for mine too

NostalgiaT
Автор

Thank you very much for this great tutorial!

LinTech-dk
Автор

one thing im confused about is the user and pass, can i use the same thing or

NostalgiaT