How to Create a Swing CRUD Application on NetBeans Platform 6.8
This article shows you how to integrate a Java DB database into a NetBeans Platform application. We start by exploring a Java DB database, from which we create entity classes. Next, we wrap the entity classes into a module, together with modules for the related JPA JARS.
Note: These instructions are not applicable to Java DB only. Rather, they are relevant to any relational database, such as Oracle or MySQL. Several applications on the NetBeans Platform, many of which are listed here, use these databases too. Java DB was chosen for this article because it is easiest to get started with, since it comes with the JDK.
Once the above modules are part of our application, we create a new module that provides the user interface for our application. The new module gives the user a tree hierarchy showing data from the database. We then create another module that lets the user edit the data displayed by the first module. By separating the viewer from the editor in distinct modules, we will enable the user to install a different editor for the same viewer, since different editors could be created by external vendors, some commercially and some for free. It is this flexibility that the modular architecture of the NetBeans Platform makes possible.
When we have a module for our editor, we begin adding CRUD functionality. First, the "R", standing for "Read", is handled by the viewer described above. Next, the "U" for "Update" is handled, followed by the "C" for "Create", and the "D" for "Delete".
At the end of the article, you will have learned about a range of NetBeans Platform features that help you in creating applications of this kind. For example, you will have learned about the UndoRedo.Manager and the ExplorerManager, as well as NetBeans Platform Swing components, such as TopComponent and BeanTreeView.
Contents
- Setting Up the Application
- Integrating the Database
- Creating Entity Classes from a Database
- Wrapping the Entity Class JAR in a Module
- Creating Other Related Modules
- Designing the User Interface
- Setting Dependencies
- Running the Prototype
- Integrating CRUD Functionality
The application you create in this article will look as follows:
Source code: http://kenai.com/projects/nbcustomermanager
Once you're at the stage shown above, you can simply download a NetBeans module that provides Office LAF support (described here), add it to your application, and then when you redeploy the application, you will see this:
Note: It is advisable to watch the screencast series Top 10 NetBeans APIs before beginning to work on this article. Many of the concepts addressed in this article are discussed in more detail within the screencast series.
Setting up the Application
Let's start by creating a new NetBeans Platform application.
- Choose File > New Project (Ctrl+Shift+N). Under Categories, select NetBeans Modules. Under Projects, select NetBeans Platform Application. Click Next.
- In the Name and Location panel, type DBManager in the Project Name field. Click Finish.
The IDE creates the DBManager project. The project
is a container for all the other modules you will create.
Run the application and notice that you have quite a few features out of the box already. Open some of the windows, undock them, and get to know the basic components that the NetBeans Platform provides without you doing any work whatsoever:
Integrating the Database
In order to integrate the database, you need to create entity classes from your database and integrate those entity classes, together with their related JARs, into modules that are part of your NetBeans Platform application.
Creating the Entity Classes
In this section, you generate entity classes from a selected database.
- For purposes of this example, use the Services window to
connect to the sample database that is included with
NetBeans IDE:
Note: Alternatively, use any database you like and adapt the steps that follow to your particular use case. In the case of MySQL, see Connecting to a MySQL Database.
- In the IDE, choose File | New Project, followed by Java | Java Class Library to create a new library project named CustomerLibrary.
- In the Projects window, right-click the library project
and choose File | New File, followed by Persistence | Entity
Classes from Database. In the wizard, select your database and the tables you
need. Here we choose "Customer", and then "Discount Code" is added automatically, since
there is a relationship between these two tables.
- Specify the persistence strategy, which can
be any of the available options. Here, since we need
to choose something, we'll
choose EclipseLink:
- Specify "demo" as the name of
the package where the entity classes will be generated.
- Click Finish. Once you have completed this step, look at the generated code and notice
that, among other things, you now have a persistence.xml file in a folder
called META-INF, as well as entity classes for each of your tables:
- Build the Java Library and you will have a JAR file in the library
project's "dist" folder, which you can view in the Files window:





Comments
Steve Sdas replied on Fri, 2012/10/12 - 3:42pm
Steve Sdas replied on Fri, 2012/10/12 - 3:46pm
in response to:
Geertjan Wielenga
Steve Sdas replied on Mon, 2012/11/12 - 3:29pm
Uilly Tocky replied on Mon, 2012/12/31 - 5:28am
Uilly Tocky replied on Sat, 2013/02/02 - 6:44am
Uilly Tocky replied on Mon, 2013/02/04 - 4:50am
Uilly Tocky replied on Tue, 2013/02/05 - 11:23am
Uilly Tocky replied on Wed, 2013/02/06 - 9:01am
Uilly Tocky replied on Fri, 2013/02/08 - 6:43am
Roger Sall replied on Tue, 2013/04/09 - 1:29pm
Roxanne Mioto replied on Fri, 2013/04/12 - 1:17pm
It is this flexibility that the modular architecture of the NetBeans Platform makes possible melatonina, ácido ursólico , lipo 6 ultra
Uilly Tocky replied on Sun, 2013/04/14 - 10:27am
Junio Mousull replied on Wed, 2013/04/17 - 8:40pm
I would take this opportunity to emphasize the importance of 1. Define roles and tasks (I prefer "roles and responsibilities"), and bbom
Junio Mousull replied on Wed, 2013/04/24 - 9:35am
NetBeans users could learn a lot about Spring RCP by reading the steps in this dhea 100mg
Junio Mousull replied on Sat, 2013/05/04 - 7:01pm
Junio Mousull replied on Tue, 2013/05/07 - 1:04pm
By nite burn
Uilly Tocky replied on Sun, 2013/05/12 - 5:24am
Uilly Tocky replied on Fri, 2013/05/24 - 1:11am
Uilly Tocky replied on Sun, 2013/05/26 - 11:49am
Uilly Tocky replied on Sun, 2013/05/26 - 12:16pm
Uilly Tocky replied on Mon, 2013/05/27 - 7:38am
Uilly Tocky replied on Fri, 2013/05/31 - 5:20am