Databases Reference
In-Depth Information
For Type 4 driver connectivity, use the following URL format:
jdbc:db2://host name:port number/database name
The db2jcc.jar package contains the universal driver classes.
5.3 Application example
In this chapter, we discuss the fundamentals of application development using
DB2 JDBC and guide you through the Java application development process
using a small shopping cart application. This application uses the SAMPLE
database shipped along with the DB2 Express-C. The application does the
following:
Takes the customer ID as an input. Checks if the customer exists. If the
customer exists, the application goes to the next page to take the order.
Displays all the available products. The user can select a product from the list
and add it to the cart.
While checking out, the application gives the purchase order ID and inserts
the purchase order details in the table.
The class in Example 5-1 on page 202 has some of the support methods used
for the application. We use this example along with others to explain how to
access DB2 data. At the end of this chapter, you can follow the steps provided to
run the application. You can find the sample application download procedure at
Appendix C, “Additional material” on page 319.
This class contain the following method:
isCustomer(int):
This method checks to see if the customer ID passed to the method as an
argument exists in the database or not. It returns the customer name if the id
exists.
getProducts():
This method returns the name of all the available products.
getDescription(String):
This method returns the description of the product id passed as an argument.
createCart(HashMap):
This creates a cart table to store the temporary data for the cart.
updateTable():
Update the tables with the purchase order details.
Search WWH ::




Custom Search