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.

 

Step 1

 

Create a new folder on your desktop and call it schemas. Put the northwind-schema.xml file into it.

 

Step 2

 

Type the following text into the console:

 

CodeGenerator -schemaFolder ../../../schemas -outputFolder ../../../output

 

Step 3

 

Make sure that the CodeGenerator has created the following directories and files.

 

1.output/build/dist/

2.output/buld/dist/classes.jar

3.output/build/dist/classes-nodep.jar

4.output/build/dist/dependencies.jar

5.output/build/doc/

6.output/build/doc/pages/

7.output/build/doc/northwind-schema.html

8.output/build/doc/northwind-schema.xsd

9.output/build/doc/javancss.txt

10. output/build/javadoc/

11. output/build/javadoc/index.html

12. output/build/src

 

#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.

 

Step 4

 

Make sure that the database server from Tutorial 03 is running. (Steps 1 and 2)

 

Step 5

 

Download and compile the following program to "select all EMPLOYEES" from the Northwind database.

 

http://www.wickedfastsolutions.com/resources/Tutorial04.java

 

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

 

 

http://www.wickedfastsolutions.com/resources/h2-1.3.176.jar

 

http://www.wickedfastsolutions.com/resources/northwind-database.properties

 

 

java -cp .;classes.jar;h2-1.3.176.jar Tutorial04

 

 

You should see 9 EMPLOYEES records printed out.

 

=======================================

<EMPLOYEES>

    <ID>5</ID>

    <COMPANY>Northwind Traders</COMPANY>

    <LAST_NAME>Thorpe</LAST_NAME>

    <FIRST_NAME>Steven</FIRST_NAME>

    <EMAIL_ADDRESS>steven@northwindtraders.com</EMAIL_ADDRESS>

    <JOB_TITLE>Sales Manager</JOB_TITLE>

    <BUSINESS_PHONE>(123)555-0100</BUSINESS_PHONE>

    <HOME_PHONE>(123)555-0102</HOME_PHONE>

    <FAX_NUMBER>(123)555-0103</FAX_NUMBER>

    <ADDRESS>123 5th Avenue</ADDRESS>

    <CITY>Seattle</CITY>

    <STATE_PROVINCE>WA</STATE_PROVINCE>

    <ZIP_POSTAL_CODE>99999</ZIP_POSTAL_CODE>

    <COUNTRY_REGION>USA</COUNTRY_REGION>

    <WEB_PAGE>http://northwindtraders.com#http://northwindtraders.com/#</WEB_PAGE>

    <NOTES>Joined the company as a sales representative and was promoted to sales manager.  Fluent in French.</NOTES>

    <ATTACHMENTS></ATTACHMENTS>

</EMPLOYEES>

=======================================

Returned: 9 records

 

 

 

Congratulations, you have just finished Tutorial-04!