Today is Wednesday, 29th March 2017

Archive for August, 2014


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

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

Please subscribe to this channel 🙂

Download Java Source Code

Download Java Source Code

 

Video Transcript

Time – 00:00
Hi, this is Chad (shod) with luv2code.com. In this video, you will learn how to connect to MySQL with Java and NetBeans.

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
I will show you how to download the MySQL database driver and add it to your NetBeans project. First thing we have to do is visit the MySQL website at dev.mysql.com. On this page, we’ll choose the dropdown and we’ll select the platform independent. We’ll choose the second entry here, the ZIP Archive and we’ll click the download button. On the next page right near the bottom, we’ll say no thanks, just start my download. Then we’ll save it to our local system.

Time – 02:07
Now let’s move over to our Finder window on our file system and find the actual file that we just downloaded and I want to uncompressed it because right now it’s a ZIP. I’ll double click it, this will expand it or extract it. I’ll look at it through list view. Now I have this new directory with the artifacts and there’s a MySQL connector Java bin.jar, that’s the actual JDBC driver that we’ll use.

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
Okay so this wraps up our video. You learned how to use NetBeans to connect to a MySQL database. Please subscribe to our channel to view more videos on Java, click thumbs up to like our video. Also visit our website luv2code.com to download the Java source code used in this video.

Share


Java Eclipse Tutorial – Part 12: Setting Preferences

In this video you will learn how to set some of the most common Eclipse preferences.

Please subscribe to this channel 🙂

 

# Video Length
1 Installing the Eclipse IDE 03:18
2 Create a Java Application with Eclipse 03:44
3 Exploring the Eclipse User Interface 04:50
4.1 Searching and Navigating Source Code (part 1) 04:18
4.2 Searching and Navigating Source Code (part 2) 06:06
5 Generating Java Source Code 05:12
6.1 Refactoring Code - Extract Constants and Variables 04:13
6.2 Refactoring Code - Extract Methods, Rename Methods and Variables 04:19
7 Debugging Java Source Code 04:34
8 Adding JAR Files 05:17
9 Running JUnit Tests 05:08
10 Importing Projects 01:45
11 Exporting Projects 01:34
12 Setting Eclipse Preferences 04:09
Total 58:27

 

Video Transcript

Time – 00:00
Hi, this is Chad (shod) with luv2code.com. Welcome back to another tutorial on Eclipse. In this video, you’ll learn how to set some of the most common Eclipse preferences.

Time – 00:10
Preferences allow you to customize your Eclipse environment. I’ll show you, how to set the following preferences. We’ll look at setting the Java version, font sizes, line numbers and the default username. Okay, so let’s get started.

Time – 00:28
You can access the preferences window by selecting window preferences. You can configure Eclipse to use certain version of Java. For example, if you have multiple versions of Java installed, you can configure Eclipse to use a desired version.

Time – 00:43
To set the current version of Java that Eclipse will use, in the preferences window, you’ll select Java, installed JREs. This will show which JREs are installed and you can choose a different version, if desired. You can also set the compliance level by choosing Java compiler. This will tell Eclipse to make sure the code is compliant with the selected version of Java.

Time – 01:09
Another preference that I always set is display line numbers. By default Eclipse will not show you the line numbers. Take a look at the current screenshot. However, I find it very useful for the editor to display the line numbers for the source code.

Time – 01:24
You can set this in the preferences, it’s under general, editors, text editors and has a checkbox here for line numbers. You toggle that it will display the line numbers in the user interface. I also like to increase the font size. Sometimes I find it hard to view the small font, of course this is the personal preference, you may prefer small fonts.

Time – 01:58
You can set the font size by going to general, appearances, colors and fonts. Expand the section for Java, move down to the Java editor font, click the edit button, choose your desired font.
Here I’ll just increase the size to 24, close that click okay and note we have a much larger font in the editor.

Time – 02:26
I also like to change the default username for code templates. This is the username that Eclipse uses, when it inserts Java documentation. You can edit this preference by selecting Java, code style, code templates and then you select comments and expand the types, click edit. Here, what I’ll do is, I will append the website to the dollar sign user. This will show up in the actual Java documentation for new classes. luv2code.com, click okay and then click okay.

Time – 03:10
Now, when we add a new Java class, we will see this new information. New class, I’ll just enter a simple name of foobar, hit finish. Now, what I’ll do is, I will go through and add a comment at the beginning of this file. Here we go, we see this luv2code and our website luv2code.com.

Time – 03:38
If you can’t figure out how to set up preference, Eclipse has nice search feature. In the preferences window, you can enter a search string in the box. For example, if I want to find out, how to show the line numbers in the search box, I’ll type “line numbers” and it will take me directly to the location where I can set this option. This is very useful for finding a given preference to set.

Time – 04:02
Okay, so this wraps up our video on setting preferences in Eclipse. Please subscribe to our channel to view more videos on Eclipse and Java. Click the thumbs up to like our video. Also visit our website luv2code.com to download Java source code.

Share


Java Eclipse Tutorial – Part 11: Exporting Projects

In this video tutorial, I will show you how to export Eclipse projects.

Please subscribe to this channel 🙂

 

# Video Length
1 Installing the Eclipse IDE 03:18
2 Create a Java Application with Eclipse 03:44
3 Exploring the Eclipse User Interface 04:50
4.1 Searching and Navigating Source Code (part 1) 04:18
4.2 Searching and Navigating Source Code (part 2) 06:06
5 Generating Java Source Code 05:12
6.1 Refactoring Code - Extract Constants and Variables 04:13
6.2 Refactoring Code - Extract Methods, Rename Methods and Variables 04:19
7 Debugging Java Source Code 04:34
8 Adding JAR Files 05:17
9 Running JUnit Tests 05:08
10 Importing Projects 01:45
11 Exporting Projects 01:34
12 Setting Eclipse Preferences 04:09
Total 58:27

 

Video Transcript

Time – 00:00
Hi this is Chad (shod) with luv2code.com. Welcome back to another tutorial on Eclipse. In this video you will learn how to export Eclipse projects.

Time – 00:10
When you want to share your project with other developers, you can simply export the project. Eclipse will create a zip file of your project and this will include your source code and project settings. Another developer will be able to use your project by simply importing the project. If you’d like to learn how to import a project, check out my other video on importing projects.

Time – 00:30
To export your project, right click the project and select export. Then go to general, choose archive file, click next. Choose browse and give it a file name. In this example we’ll give demo-test.zip. Hit save and go ahead and click the option to Use Zip. Once that’s finished, go ahead and select finish.

Time – 01:08
At this point, Eclipse created a zip file for you on your file system. Let’s go to our file system and verify that the file is there. Here you can see demotest.zip. This project was exported successfully.

Time – 01:24
All righty. This wraps up our video on exporting projects in Eclipse. Please subscribe to our channel to view more videos on Eclipse. Also click the thumbs up to like our video. Finally, visit our website luv2code.com to download Java source code.

Share