Java Reference
In-Depth Information
As shown in the SQL snippet of Listing 15-6 , the ResultSet for the detail page is based on the LIST
columns from the attribute tables. These columns are combined with information from the individual
columns of the Vehicle table. Listing 15-6 shows the SQL code required to create the stored procedure
GET_DEATIL_PAGE , which the JavaBean used to create the XML document will call.
Listing 15-6: Stored procedure for detail page
CREATE PROCEDURE GET_DETAIL_PAGE @id int
AS SELECT v.*, o.list OPTIONS
FROM Vehicles v, Options o
WHERE o.id = v.id AND
v.id = @id;
Listing 15-7 shows a JavaBean that calls the stored procedure of Listing 15-6 and formats the
ResultSet as XML. A ResultSetMetaData object is used to get the column names that are used as
tag names for the XML elements. The column data Strings are appended to the XML elements as text
nodes.
Listing 15-7: JavaBean that returns a ResultSet as XML
package JavaDatabaseBible.ch15;
import java.io.*;
import java.sql.*;
import javax.sql.*;
public class DetailPageXMLBean{
protected static String dbUserName = "sa";
protected static String dbPassword = "dba";
protected String xmlHeader = "<?xml version=\"1.0\"?>";
protected int id;
public DetailPageXMLBean(){
}
public void setId(int id){
this.id=id;
}
public String getXmlString(){
String xml = new String(getVehicleData());
return xml.trim();
}
public byte[] getVehicleData(){
String rootTag = "VehicleData";
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
Search WWH ::




Custom Search