|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
General Java Web Database Publishing
Web Database Publishing
Jul. 1, 1997 12:00 AM
Today, Web database publishing is an important way to publish information electronically. It actually combines the advantages of two important technologies - database and the Web. Standard database interfaces such as ODBC[1] (Open Database Connectivity) are used to provide an abstraction layer so that application programs can access data in a uniform and vendor-neutral way. ODBC is a standard API interface introduced by Microsoft. Each database requires a driver that converts SQL calls into the respective database's native calls and then performs the database interactions. Currently, there are many databases that come with ODBC drivers such as Oracle, Sybase, MS SQL, etc. Modeled after ODBC, JDBC[2] (Java Database Connectivity) provides a standard set of classes and interfaces to allow Java[3] applications and applets to access the databases. We all know that Java applets inject dynamics and liveliness into the Web content. With the release of JDBC, Java developers can now enhance the information repository and retrieval functions of their Java application or applets by integrating them with their back-end database management system. In fact, the Java database solution on the Web through JDBC provides a powerful means to organize and distribute information across different platforms on the Web. Unlike standalone Java applications, in order to integrate Java applets with the back-end databases through JDBC there are a number of crucial points to consider. In this article, we will discuss how Java applets can access ODBC-compliant databases such as MS SQL based on the Java three-tier database solution. In addition, we will illustrate the solution with an inquiry service of a Web-based book kiosk system for a possible Internet/Intranet setup in an organization.
Why a Three-tier Java Database Solution? As shown in the above setup, Web-based applications using Java applets could be developed and run on Internet/Intranet servers even though they may be for different platforms. However, in order to integrate with the back-end database system, you need to consider a couple of points. First of all, due to security constraints, Java applets can only make network connections to the Web server from which they were downloaded. Second, untrusted Java applets cannot access native codes. Thus, the traditional two-tier configuration with a Java client connecting to a database server, as shown in Figure 2, becomes unfeasible. In the two-tier configuration, the Java Client with JDBC API [2] connects to the database server through JDBC drivers and some form of database interface, if any, such as ODBC or a vendor-specific library. In our given setup, shown in Figure 1, the database server does not reside in the same host as the Web server for performance and security reasons. Furthermore, most of the databases such as Microsoft MS SQL server do not come with JDBC drivers purely in Java codes. Thus, there is a need for a three-tier database solution with an intermediary server between the applets and the database server. Figure 3 shows the three-tier database connection for Java applets. The intermediary server serves as a middle man between the Java applet and the SQL server. In addition, this middleware must be in the same host as the HTTP server. In this case, no native code is to be loaded over the applet side. The intermediary server, or middleware, is responsible for accepting the requests from the applets and making the necessary connections to the database server. In this article, we will use a Web-based book kiosk system store that we have developed for Fantastic Reading bookstore to illustrate the above Java database solution. The intermediary server or middleware that we have used to glue the Java Applet, JDBC and MS SQL [4] database server together is a Weblogic[5] T3Server, shown in Figure 4. The T3Server acts as a multitier application server which manages the connection between the client and the T3Server and manages database interactions between the client and the database. MS SQL server is used in our setup and Weblogic JDBC driver is used for the two-tier between the T3Server and database server. Besides this, the JDBC-ODBC bridge with ODBC manager can also be used for the connection between the T3Server and MS SQL server. However, the latter approach will introduce extra overhead for JDBC-ODBC translation. We will illustrate both approaches in connecting the intermediary server to the database server.
Anatomy of Database Query Using Three-tier Solution The customer with Internet access could search for book titles available in the book kiosk by specifying a title in full or partially. Fantastic Bookstore keeps the book titles in a database table named book in the SQL database server (MS SQL server in this case). Upon clicking the Go button, you will see all the titles matching the search criteria displayed in the scrollable text area. When a Java applet of the inquiry service is downloaded to the client side, it will connect first to the intermediary server (Weblogic's T3Server[5]) on the HTTP server and the book title that the user specified will be sent to the intermediary server. The intermediary server, upon accepting the request from the Java applet, will make the necessary connection to the MS SQL server on the other host by contacting the ODBC manager residing on the HTTP server. Figure 5 summarizes the sequence of events for the Java applet to access the back-end database. Upon receiving the result of the SQL query, the intermediary server will pass the result back to the applet which will display it on the client's browser.
In the following section, we will describe the detailed implementation of the three-tier Java database solution by using two approaches to connect the intermediary server to the database server: Listing 1 depicts the Inquiry class built for the book kiosk inquiry service by using Weblogic native JDBC driver; i.e., the first approach. The following classes need to be imported into the applet:
import java.util.properties;
if ((t3 == null) || (conn == null)) { The Properties object contains all the information for making a JDBC connection. It contains the details about how a JDBC client should access both the database and the intermediary server; i.e., T3Server. As shown in Listing 1, two properties, namely dbproperties and t3properties, are used. dbproperties is used to set parameters for the connection between the T3Server and the database server; e.g., user ("sa"), password (""), server name ("cobam").
Properties dbproperties = new Properties(); Class.forName("Weblogic.jdbc.t3client.Driver"); conn = DriverManager.getConnection("jdbc.weblogic.t3client", t3properties); 2. Create and execute the SQL statement; i.e., it will send the SQL query to the intermediary server. ... Statement stmt = conn.createStatement(); stmt.execute(str); ... where the variable str contains the SQL statement
3. Get back the query result from the T3Server and append it to the text area to be displayed.
...
Listing 2 shows the HTML codes for the inquiry service using the first approach; i.e., Weblogic JDBC native driver. In order to load Weblogic specific classes, they must be loaded relative to the path specified by the codebase (i.e., http://cobam.ccs.np.ac.sg/, the home directory of the HTTP server). The applet code is specified relative to the codebase (i.e., kiosk.inquiry.class). kiosk is the package name specified in the Java applet and inquiry.class resides in the subdirectory kiosk of the home directory of the HTTP server.
Listing 3 depicts the Inquiry_b class built for the book kiosk inquiry service using the JDBC-ODBC bridge between the intermediary server and the SQL server. It is similar to that in the Weblogic native JDBC approach except for the following segment in the establish() method:
...
Conclusion
Reference Reader Feedback: Page 1 of 1
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||