在websphere上一个J2EE应用中引用多个数据源JNDI的方法[转帖]

    技术2022-05-19  21

    1.在WEB-INF下新建文件ibm-web-bnd.xmi中建立两个绑定JNDI名<?xml version="1.0" encoding="UTF-8"?><com.ibm.ejs.models.base.bindings.webappbnd:WebAppBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:com.ibm.ejs.models.base.bindings.webappbnd="webappbnd.xmi" xmi:id="WebAppBinding_1216699055547" virtualHostName="default_host">  <webapp href="WEB-INF/web.xml#WebApp_1216699055562"/>  <resRefBindings xmi:id="ResourceRefBinding_1" jndiName="jdbc/ias">    <bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1"/>  </resRefBindings>  <resRefBindings xmi:id="ResourceRefBinding_1216699055547" jndiName="jdbc/host">    <bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1216699055547"/>  </resRefBindings></com.ibm.ejs.models.base.bindings.webappbnd:WebAppBinding>2.在WEB.xml文件中两个引用指向(id分别跟上面的web.xml#后面的内容相同)<resource-ref id="ResourceRef_1">    <description></description>    <res-ref-name>ias</res-ref-name>    <res-type>javax.sql.DataSource</res-type>    <res-auth>Container</res-auth>    <res-sharing-scope>Shareable</res-sharing-scope>   </resource-ref>     <resource-ref id="ResourceRef_1216699055547">    <description></description>    <res-ref-name>host</res-ref-name>    <res-type>javax.sql.DataSource</res-type>    <res-auth>Container</res-auth>    <res-sharing-scope>Shareable</res-sharing-scope>   </resource-ref>3.在代码中可以引用两个JNDI(不同的数据源) Context ctx = new InitialContext();    Object obj = ctx.lookup("java:comp/env/host");      ds = (DataSource) obj;      conn = ds.getConnection();      stmt = conn.createStatement();      rs = stmt.executeQuery("select * from c_jgb where rownum<10");

     Context ctx = new InitialContext();    Object obj = ctx.lookup("java:comp/env/ias");      ds = (DataSource) obj;      conn = ds.getConnection();      stmt = conn.createStatement();      rs = stmt.executeQuery("select * from TBUSERSUBPOS where rownum<10");

     

    本文来自博客,转载请标明出处:http://blog.csdn.net/lxxstarii/archive/2008/07/23/2698613.aspx


    最新回复(0)