⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customerlistbean.java

📁 此程序都是企业级 的数据库开发程序 全面揭示了JAVA对数据库的操作
💻 JAVA
字号:
package mvc.custlist;/* Standard Java class package */import java.rmi.RemoteException;import java.io.File;import java.util.Collection;import java.util.Iterator;/* Pulled from the J2EE or JBoss servlet.jar */import javax.servlet.http.HttpServletRequest;/* Pulled from the J2EE or JBoss ejb.jar */import javax.naming.InitialContext;import javax.ejb.SessionContext;/* Classes pulled from the xerces.jar */import org.w3c.dom.Document;import org.w3c.dom.Element;import org.apache.xerces.dom.DocumentImpl;import mvc.templates.*;import mvc.*;import mvc.entitybeans.customers.*;import mvc.entitybeans.postalcodes.*;public class CustomerListBean implements MVCBean {  /*   * The retrieve method for the CustomerListBean retrieves all of the customers   * and their addresses from the Music Record database.  The data is   * packaged as XML and returned to the application invoking the CustomerList   * EJB.   */  public Document retrieve(HttpServletRequest _request)           throws RemoteException, Exception {    InitialContext ctx = new InitialContext();    CustomersHome customersHome = (CustomersHome) ctx.lookup("Customers");    Collection customersCollections = customersHome.findAll();    /* Building the XML Document that contains the customerRS data */    Document xmlDocReturned = buildXML(customersCollections, ctx);    return xmlDocReturned;  }   /*   * The post() method is returning null because the CustomerList screen   * does not actually save any data.   */  public Document post(HttpServletRequest _request)           throws RemoteException, Exception {    return null;  }   /*   * The buildXML method builds an XML document containing the customer   * address data retrieved from the music record database.   */  private Document buildXML(Collection _customerCollections,                             InitialContext _ctx) throws Exception {    Document xmlDoc = new DocumentImpl();    /* Creating the rootElement */    Element rootElement = xmlDoc.createElement("CUSTOMERS");    Element customerElement = xmlDoc.createElement("CUSTOMER");    xmlDoc.appendChild(rootElement);    Iterator iterator = _customerCollections.iterator();    /* Cycling through all of the records within the resultset */    while (iterator.hasNext()) {      /* Retrieve my customer object from my iterator */      Customers customer = (Customers) iterator.next();      /* Setting up my primary key for my customer order */      customerElement.setAttribute("customerid",                                    customer.getCustomerId().toString());      /* Adding my different elements to the order header */      customerElement.appendChild(MVCHelper.buildDBElement(xmlDoc,               "CUSTOMERFIRSTNAME", customer.getCustomerFirstName()));      customerElement.appendChild(MVCHelper.buildDBElement(xmlDoc,               "CUSTOMERLASTNAME", customer.getCustomerLastName()));      customerElement.appendChild(MVCHelper.buildDBElement(xmlDoc,               "CUSTOMERADDRESS1", customer.getCustomerAddress1()));      customerElement.appendChild(MVCHelper.buildDBElement(xmlDoc,               "CUSTOMERADDRESS2", customer.getCustomerAddress2()));      customerElement.appendChild(MVCHelper.buildDBElement(xmlDoc,               "CUSTOMERCITY", customer.getCustomerCity()));      /* Retrieving my postal code information */      PostalCodesHome postalCodesHome =         (PostalCodesHome) _ctx.lookup("PostalCodes");      PostalCodes postalCodes =         postalCodesHome.findByPrimaryKey(customer.getCustomerPostalCode());      customerElement.appendChild(MVCHelper.buildDBElement(xmlDoc,               "CUSTOMERSTATE", postalCodes.getStateProv()));      customerElement.appendChild(MVCHelper.buildDBElement(xmlDoc,               "CUSTOMERZIP", postalCodes.getPostalCode()));      rootElement.appendChild(customerElement);      customerElement = xmlDoc.createElement("CUSTOMER");      MVCHelper.printDOM(xmlDoc, new File("c:\\temp\\output.xml"));    }     return xmlDoc;  }   /*   * Standard EJB Methods.  For simplicity's sake these methods have   * been implemented as empty methods.   */  public void ejbCreate() {}  public void ejbRemove() {}  public void ejbActivate() {}  public void ejbPassivate() {}  public void setSessionContext(SessionContext sessionCtx) {}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -