Đang chuẩn bị liên kết để tải về tài liệu:
Xml programming bible phần 10
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Lệnh SQL, AuthorName chọn từ các tác giả, lựa chọn tất cả các giá trị trong cột AuthorName của bảng tác giả. Lớp buildArray được sử dụng bởi các lớp GetAuthorList và GetSingleAuthorList để xây dựng một mảng từ một tập hợp kết quả DB2JDBC. | Chapter 36 Accessing Relational Data via Web Services 851 The SQL command select AuthorName from Authors selects all of the values in the AuthorName column of the Authors table. The buildArray class that is used by the GetAuthorList and GetSingleAuthorList classes to build an array from an DB2JDBC result set. An ArrayList is created which is an implementation of the List interface. The most important feature of ArrayLists for the purposes of this code is that they are automatically resizable via the add method. Note We have explicitly specified java.util.List because the java.awt package also has a List interface. The JDBC specification contains a .toArray method for result sets which would be great for this purpose. However not all JDBC drivers implement a complete set of methods for JDBC classes. The code in the buildArray class can be used when the toArray method is not supported as is the case with the DB2JDBC driver or when you want all JDBC result set array output to be the same regardless of driver-specific formatting. A DB2result set is passed from the calling object and an ArrayList is defined called arrayResults. The code loops through the result set and retrieves the current result set row value as a string. DB2result set values returned by the DB2JDBC driver sometimes contain leading and trailing blanks so the trim method is sued to trim spaces off the string as it is created. The string is added to the array Results object using the ArrayList.add method. Next a string array called sarray is created and the value of the ArrayList is passed to the string array using the ArrayList.toArray method. The buildArray class creates a string array from the JDBC result set which is passed to the J2EE application that called the Web service via a SOAP envelope Listing 36-1 . Listing 36-1 The XMLPBWSMTServletGetAuthorList Web Service Code import java.util. import java.io. import java.sql. public class XMLPBWSMTServletGetAuthorList public String GetAuthorList String