Tutorial 04 - Accessing the Northwind Database
|Top Previous Next|
12/30/2016 - The current version of the software is 3.4.1
Please upgrade if you are not using the latest version of the software.
Last Updated: 12-12-2016
In the last tutorial we used the SchemaGenerator to generate a schema for the Northwind database. In this tutorial we will compile the schema and then write a java program to access the database.
Create a new folder on your desktop and call it schemas. Put the northwind-schema.xml file into it.
Type the following text into the console:
CodeGenerator -schemaFolder ../../../schemas -outputFolder ../../../output
Make sure that the CodeGenerator has created the following directories and files.
#2 contains all the classes and dependencies required for the software to run
#3 contains just the compiled domain objects with no dependencies
#4 contains just the required dependencies
#7 contains the UIDS for mapping between domains
#8 contains a w3c version of the schema (in russian doll format)
#9 contains an overview of the number of lines of code generated
#11 contains the javadoc of the generated source code
#12 contains the generated source code
Now that you have compiled your schema and generated a model of the database, you may use that model to query, insert, update, and delete data from it.
Make sure that the database server from Tutorial 03 is running. (Steps 1 and 2)
Download and compile the following program to "select all EMPLOYEES" from the Northwind database.
To compile the program you will need the output/build/dist/classes.jar archive from Step 2
javac -cp classes.jar Tutorial04.java
To run the program you will need a copy of the h2 database driver and a copy of the northwind-database.properties
java -cp .;classes.jar;h2-1.3.176.jar Tutorial04
You should see 9 EMPLOYEES records printed out.
<ADDRESS>123 5th Avenue</ADDRESS>
<NOTES>Joined the company as a sales representative and was promoted to sales manager. Fluent in French.</NOTES>
Returned: 9 records
Congratulations, you have just finished Tutorial-04!