Archive for the ‘NetBeans’ Category
Java NetBeans Tutorial: Connecting to a MySQL Database with JDBC and NetBeans
Last Updated on Tuesday, 10 February 2015 Written by Chad Darby Sunday, 31 August 2014
In this video you will learn how to connect to MySQL with Java and NetBeans.
Please subscribe to this channel 🙂
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.
How To Fix The libs.CopyLibs.classpath Problem in NetBeans 7
Last Updated on Thursday, 7 June 2012 Written by Chad Darby Thursday, 7 June 2012
I recently made some updates to my NetBeans development environment and encountered this weird error:
d:\dev\myproject\nbproject\build-impl.xml:485: The libs.CopyLibs.classpath property is not set up. This property must point to org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part of NetBeans IDE installation and is usually located at /java/ant/extra folder. Either open the project in the IDE and make sure CopyLibs library exists or setup the property manually. For example like this: ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar BUILD FAILED (total time: 0 seconds)
I was able to resolve it by following these steps:
- In NetBeans, select Tools > Options > Miscellaneous > Ant
- In the Properties section, add the following property
Click OK and Build your project again. This error will go away. Hope this helps. Happy coding!
Netbeans: Setting up a Web project with SmartGWT
Last Updated on Sunday, 8 July 2012 Written by Chad Darby Saturday, 12 November 2011
This document shows you how to set up a Netbeans Web project with SmartGWT.
- GWT 2.2+: http://gwt.google.com
- SmartGWT 2.4+: http://code.google.com/p/smartgwt/
1. Create GWT project using “webappcreator”
Open an MS-DOS window, type:
webappcreator -out c:\dev\testgwt org.demo.TestGwtApp
2. Create a new NetBeans project, using the following steps
- Select File > New Project
- In the Choose Project step, select
- Categories: Java Web
- Projects: Web Application with Existing Sources
- Click Next
- In the Name and Location step,
- Click the Browse… button for the Location. Browse to the directory that was created in Step 1: c:\dev\testgwt
- Click Next
- Click OK to rename the build file to nbbuild.xml
- In the Existing Sources and Libraries step, click Next
- In the second Existing Sources and Libraries step, click Browse for Web Pages Folder
- Select the directory: war
- Click Finish
3. Copy SmartGWT libs
Note: these JARs are only needed for compilation. Do not put in WEB-INF/lib.
Update the NetBeans project to include lib/smartgwt.jar
4. Update build.xml to include these paths at compilation time: project.classpath
5. Add Skins to host HTML page
In HTML host page
6. In host HTML page
Move the loading of module AFTER the isomorphic load. See below
7. Update MyApp.gwt.xml
<inherits name="com.smartgwt.SmartGwtNoTheme" /> <inherits name="com.smartclient.theme.enterpriseblue.EnterpriseBlue"/>