开发容器管理持久化实体bean.ppt

  1. 1、本文档共34页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
测试Product实体Bean 在Web项目中新建一Servlet,名为TestAccountServlet,修改其doGet方法,其主要代码如下: Hashtable properties = new Hashtable(); properties.put(InitialContext.INITIAL_CONTEXT_FACTORY, org.jnp.interfaces.NamingContextFactory); properties.put(InitialContext.PROVIDER_URL, localhost:1099); ProductHome home = null; try { InitialContext ctx = new InitialContext(properties); Object objRef = ctx.lookup(“ejb/Product); home = (ProductHome) PortableRemoteObject.narrow( objRef, ProductHome.class); home.create(123-456-7890, “P5-350“, “350 Mhz Pentium”, 200); home.create(123-456-7891, “P5-400“, “400 Mhz Pentium”, 300); home.create(123-456-7892, “P5-450“, “450 Mhz Pentium”, 400); home.create(123-456-7893, “SD-64“, “64 MB SDRAM”, 50); home.create(123-456-7894, “SD-128“, “128 MB SDRAM”, 100); … Iterator i = home.findByName(“SD-64).iterator(); while (i.hasNext()) { Product prod = (Product) PortableRemoteObject.narrow( i.next(), Product.class); out.println(prod.getDescription()); } else { throw new Exception(Could not find product); } i = home.findByBasePrice(200).iterator(); while (i.hasNext()) { Product prod = (Product) PortableRemoteObject.narrow(i.next(), Product.class); out.println(prod.getDescription()); } } catch (Exception e) { out.println(e.getMessage() + br); } finally { if (home != null) { Iterator i = home.findAllProducts().iterator(); while (i.hasNext()) { Product prod = (Product) PoratableRemoteObject.narrow(i.next(), Product.class); if (prod.getProductID().startsWith(“123”)) { prod.remove(); } } } } 配置JBoss数据源 在JBoss的默认部署目录下新建MySQL-ds.xml,内容如下: ?xml version=1.0 encoding=UTF-8? datasources local-tx-datasource jndi-namejdbc/mysqlds/jndi-name !--use-java-contextfalse/use-java-context-- connection-urljdbc:mysql://localhost:3306/test/connection-url driver-classcom.mysql.jdbc.Driver/driver-class user-nameroot/user-name password123/password exception-sorter-class-nameorg.jboss.resource.adapter.jdbc.ve

文档评论(0)

iris + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档