14.1 Direct Access to Remote DatabasesIn the previous three chapters, we discussed the application architecture of the disconnected but synchronized mobile databases. Although that architecture is adequate for most mobile application scenarios, in some cases, direct connections to remote databases are still preferred or even required:Some applications depend on real-time backend data to function correctly. In theory, we can synchronize the databases as frequently as we wish to catch up with the real-time changes, but that would soon become too inefficient. For example, a salesperson might only need to look up the current availability of a specific product. There is no need to synchronize the entire product catalog. It is much better and more flexible to allow the application to query the backend database directly.Some devices, especially MIDP devices, do not have enough resources to support large on-device data sets.Legacy data on mainframe applications is available only remotely. Fortunately, the wireless network intermittency and latency, which make always-connected applications impossible in consumer markets, are less a problem in the enterprise markets: Many enterprise users reside on company campus and have always-on, low latency connectivity through WiFi or other company-provided networks. Now, let's have a look at remote database access schemes. 14.1.1 Application-Specific MiddlewareIn many cases, direct database access only happens inside the middleware layer. The database component is invisible from the client side. The mobile client only needs to know how to integrate with the specific middleware application. This is the approach used in the iFeedBack (see Chapter 3) and Smart Ticket (see Chapter 5) examples. Since this approach is application specific, I suggest interested readers consult those examples to study how it is implemented. 14.1.2 Using JDBCThe JDBC API is a generic way to access relational databases over the network. Some J2ME JDBC implementations allow you to obtain a remote database connection object by supplying a remote URL to the connection factory method. IBM DB2 and Oracle JDBC drivers provide such remote access functionalities. Since JDBC is a well-documented technology, we will not discuss it in detail here. For a quick tutorial on JDBC, please refer to Chapter 11. 14.1.3 Gateway ServletMobile clients, especially MIDP clients that do not support JDBC, can rely on gateway servlets to access backend databases. A gateway servlet takes in a request from the client, queries the remote database, and then sends the data back to the client via HTTP. Commercial products that implement gateway servlets include Oracle9i J2ME SDK and Data Representation Simplicity XML transaction engine. In the rest of this chapter, we discuss how to use those two products to access generic SQL databases and legacy databases. |