Introduction
You want your e-commerce to run 24 hours a day, 7 days a week), because this is very beneficial to the Enterprise. However, this is not good for those who make e-commerce run. In the previous article of this article, we provide you with a Java-based™Swing applications, IBM®DB2®Universal Database™Users can use this application to add, modify, and delete data records in the database. However, in fact, you may be in a remote location away from the database, but you still need to be able to perform such operations on enterprise data. So why not use the World Wide Web?
In this article, we will provide you with a complete Web application called DB2 webSQL, which allows you to access DB2 V8 data through HTTP. To use the code here, make sure that a Web application server that can process JSP and Servlet is running. We are targeting WebSphere®Application Server to develop code. However, our design should be able to work on other Web application servers without too many modifications.
For the development environment, we use WebSphere Studio Application Development 4.0. The built-in WebSphere V4.0 test environment allows us to find the link kink in the program ). WebSphere Studio Application Developer allows us to build applications seamlessly using a method compliant with J2EE specifications.
In this article, we use the DB2 V8 Type 4 JDBC Universal driver to implement our project. This kind of driver is a new driver for DB2 V8, which provides the following features:
- Supports updatable ResultSet.
- Improved DB2 authentication) Security.
- Improved Java SQL error messages.
- Programmatic) tracking function.
Note: To use the JDBC Universal driver, you must include the db2jcc. jar file in the Java CLASSPATH environment variable. When viewing the code, you may notice that the JDBC syntax you are used to has changed a lot during the use of the Type 4 driver.
We are so enthusiastic about using this new driver because we want to use the updatable ResultSet support. You can find the JDBC driver in connector Type 4 and the new features provided by DB2 V8.
Prerequisites
When writing this article, we assume that you have a systematic understanding of the following technologies:
- Java Servlets
- Java Server Pages (JSPs)
- JDBC
The ability to move the cursor and update the result set is part of the powerful functions provided by the JDBC 2.0 API. You may need to read.
To install the application, we recommend that you use the following prerequisites:
- Client: Internet Explorer Browser 4.0 or later.
- Server:
- A Java Servlet Engine Running JRE 1.3. JRE 1.3 supports JSP 1.0 specifications or later and Java Servlet 2.2 specifications or later.
- DB2 Version 8.
This application is published as a WAR file.
In Windows NT®Install applications in WebSphere Application Server 4.0
- Download the WAR file.
- GoStart> Programs> IBM WebSphere> WebSphere administrator Server 4.0> Start Admin SeverTo open the Admin Console.
- Use the Install Wizard to deploy an Enterprise Application as an independent stand-alone Web Application.
- Select the downloaded WAR file and select a context for the application, such as DB2WebSQL ).
- The Wizard will ask you to select a virtual host to select default_host) and the Application Server to select the Default Application Server ).
- The Wizard will ask questions related to the EJB deployment descriptor. Ignore these issues and clickNextUntil the last page of the wizard. ClickFinish.
- After the installation is complete, you will receive a message indicating that the application has been successfully installed.
- Under Enterprise Applications in the Admin Console, you will see the installed application. Right-click the application and start the application.
- Right-click the node and generate a plug-in for the node again ).
- You can use the following URL to access the application: http ://Yourservername/application_context_name/Login.html.
Architecture of DB2 webSQL
Figure 1. WebSQL Architecture
The DB2 webSQL application is based on the Model-View-ControllerMVC mode. In the MVC mode:
- Model) represents the enterprise data.
- View.
- Controller) converts the interaction with the view to the action performed by the model.
In our applications, the model is data residing in the DB2 database, and we are trying to access the data through HTTP. A view consists of several JSPs, namely, choosetable. JSP, dberror. jsp, and manipulatetable. jsp. These JSPs are displayed by the Web browser on the client. Finally, the controller consists of two servlet AuthenticateServlet. java and DBManipulateServlet. java). The two servlets execute the request and send the result to the appropriate view, that is, JSP ).
By applying the MVC pattern to the DB2 webSQL application, we separate the presentation logic and control logic from the data. Web applications developed in this way have the following advantages:
- Reduces the impact of changes.
- Added maintainability.
- The client is independent.
In addition, this MVC Architecture allows developers to be clearly divided during application development. In our application, the representation logic is the JSP page) and the data access and business logic are two servlets and Their helper classes) are separated. Why is this advantageous? Because this clear separation allows you to change the look and feel of the Application), this change is much easier than making changes that tightly mix all the code.
In the IBM Redbook WebSphere Studio Application Developer Programming Guide on http://www.redbooks.ibm.com/?acts/sg246585.html, there is a chapter in the SG24-6585-00 that describes the use of WebSphere Studio Application Developer to develop in MVC mode, the content is quite exciting.