Netbeans + Visual Paradigm = EJB Tutorial (Part 4)

Based on the previous parts of this tutorial (1, 2, 3) we will modify the application and Glassfish to connect to PostgreSQL or Oracle as DB.

  • Preparing Glassfish libraries
    Download the drivers for Oracle and PostgreSQL and add them to your {GLASSFISHHOME}/domains/{YOURDOMAIN}/lib
    Restart Glassfish.

    Glassfish lib folder

    Continue reading

Netbeans + Visual Paradigm = EJB Tutorial (Part 3)

In part 1 of this tutorial we created an EJB using Netbeans and Visual Paradigm, in part 2 a little ZK application to read data using the EJB. In part 3 we will move away from the Derby DB to PostgreSQL and Oracle DB and challenge ourselves with identifier more than 30 characters, which is an issue for Oracle (yes, it is 2011). We will add columns with more than 30 characters and play with a few different column types (the ones showing up in a normal DB layout).

  • Add new fields to the ERD
    this_is_a_very_long_remark_field
    floatcol
    numbercol

    Updated ERD

  • Continue reading

Netbeans + Visual Paradigm = EJB Tutorial (Part 2)

In part 1 of this tutorial we walk through the modeling and code creation of an EJB using Netbeans and Visual Paradigm. In part 2 we will create a simple sample ZK web application that reads data using the EJB.

Prerequisites:

  • The project from completed tutorial part 1

Tutorial:

Netbeans + Visual Paradigm = EJB Tutorial

The only commercial product in my toolbox is Visual Paradigm, a professional UML and modeling tool that integrates with the Netbeans IDE. If you are sincere about ERD, Use-Case and class models you should look at it. The available Netbeans plugins for UML could not convince me yet, too simple (but free). Visual Paradigm seems to operate at the other end, looks rather overloaded with functionality, but once you know what you want and where the function is located, you can create a nice workflow.

In this tutorial (created for internal purpose) I share the steps to create an EJB and  the ERD model and let VP (Visual Paradigm) create the class source code for me.

Requirements:

  • Netbeans 7.x
  • Visual Paradigm (Professional Version)
    You can download the 30 days trial, the free community edition is not sufficient.

Tutorial Part 1:

ZK with EJB3.1 running on Glassfish (Part 2)

In part 1 we connected a web application to a database using an EJB for reading access, deployed on a Glassfish Server. In part 2 we do some modifications to create a true CRUD application by adding add, delete and update.

Pre-Requirements:

  • Netbeans 6.7 or later
  • Installed ZK plugin (link)
  • Glassfish V3 or later
  • Netbeans Project from Part 1 (link)

Continue reading

ZK with EJB3.1 running on Glassfish

A while back I created a tutorial that covers the direct DB access from a ZK application (link). Today I want to show you the most simple ZK application that reads from a DB using EJB 3.1 and display the data in a listbox.

Prerequisites:

  • Netbeans 6.7 or later
  • Installed ZK plugin (link)
  • Glassfish V3 or later

The tutorial covers 2 steps, the first part to create an EJB and the second part to create a ZK application. It covers all details of the project creation with Netbeans, but it does not elaborate the underlying EJB, JPA technology, feel free to read more about it at the Netbeans doc (eg. link) or in-detail at Oracle (link).

Continue reading

Interacting with Databases through the Java Persistence API

Featured article about working with JPA in Netbeans. Reviewed and reproduced following an article by PACKT Publishing (link). Please hava a look at the end of the article with the book recommendation.

We will look into:

Java EE 5 Development with NetBeans 6
  • Creating our first JPA entity
  • Interacting with JPA entities with entity manager
  • Generating forms in JSF pages from JPA entities
  • Generating JPA entities from an existing database schema
  • JPA named queries and JPQL
  • Entity relationships
  • Generating complete JSF applications from JPA entities

Continue reading

Tutorial: Reading from the DB with Netbeans and ZK (Part 2)

In this part 2 we modify the ZK project from part 1 and add data binding and a detail view.

Before we start adding the new functions, you might want to look in some of the project settings that are default when you create a new ZK360 type web project. Both context path (under Project properties|Run), as well the Display Name in the web.xml (under project explorer|configuration files) . You better change the default to avoid confusion when starting to create the second project.

I recommend to have a look at these 2 documents: ZK Developers Guide and the ZK Reference Doc (link), giving you more insights how ZK works and how feature rich it is. I noticed the available Netbeans palette does not show all available features, so you are better of browsing the docs and look at the sourcecode of the ZK Explorer application (Live Demo).

Back to part 2.

Requirements:

  • Netbeans 6.5 with a running derby DB and the sample database (customer table)
  • Installed ZK 3.6.0 plugin
  • The project from part 1 (link)

Content

1. Open the ZKReadDB project from part 1
2. Change the controller class
3. Activate the Data Binding Manager
4. Make the listbox work witha model and refer the listitems to the fields
5. Implement the detail view
6. Add the detail view with textboxes
7. The complete index.zul and controller.java

Continue reading

Tutorial: Reading from the DB with Netbeans and ZK

After the first very basic tutorial that gets you started with the required plugins and settings (link), I will summarize in this tutorial how display data with zul using the JPA.

Requirements:

  • Netbeans 6.5 with a running derby DB and the sample database (customer table)
  • Installed ZK 3.6.0 plugin

Tutorial:

Content:
1. Start a new project
2. Create a new Entity Class from Database
3. Create a Controller
4. Create the table

Continue reading

JPA and JDBC calls

JPA – Java Persistence API
This JAVA programming framework is part of EJB3.0 in JEE5. It is very powerful and removes a truckload of work for todays enterprise developer. You manage the relation between classes and relational DB’s via ORM. Once you digest the concept, it become part of your toolset.

I come from a old-fashioned background and always interest what runs under the hood and like to know about the manual way as well before indulging the “can-do-everything-easily” way.

So here my hommage to the “old” of directly accessing a DB. I am still using this approach for simple J2SE tools though ! I will talk about JPA more in detail soon.

Open and access a MySQL DB from Java

Establish a connection

String userName = “user”;
String password = “********”;
String url = “jdbc:mysql://localhost/db_sample”;
Class.forName(“com.mysql.jdbc.Driver”).newInstance();
con = (Connection) DriverManager.getConnection(url, userName, password);

Read from a table

Statement dbStatement = (Statement) con.createStatement();
ResultSet dbResultSet = dbStatement.executeQuery(“Select * from table_name”);
while (dbResultSet.next()) {
String testField = dbResultSet.getString(“fieldname”);
}

(Dont forget to cover both with try-catch’es and Netbeans will remind you of all the missing imports)

You see a number of potential flaws which gonna create trouble once you need to change it:
– hardcoded user, password, DB
– hardcoded table- and fieldnames
Imagine the project time 100 with dozens of tables and 100’s of fields, thats where the headache starts… You know what I am talking about.