在websphere上一个J2EE应用中引用多个数据源JNDI的方法
来源:互联网 发布:遗传算法 图形分割 编辑:程序博客网 时间:2024/06/05 17:52
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");
- 在websphere上一个J2EE应用中引用多个数据源JNDI的方法
- 在websphere上一个J2EE应用中引用多个数据源JNDI的方法[转帖]
- 在websphere上一个J2EE应用中引用多个数据源JNDI的方法
- [J2EE] JNDI定义Oracle数据源的方法
- j2ee规范-jndi-在Tomcat中配置数据源
- 由JDBC浅谈JNDI及其在WebSphere中的配置和企业级应用中DB Session在Spring下的管理
- WebLogic配置JNDI数据源以及如何在应用程序中使用配置好的JNDI数据源
- websphere+spring+jndi数据源配置
- websphere 使用JNDI连接数据源的配置文件编写
- 在spring+hibernate中使用tomcat5.5的jndi数据源
- 在spring中使用tomcat提供的JNDI 数据源
- Tomcat7在JNDI中添加定制的JavaBean数据源
- JNDI在tomcat中的应用:配置数据源
- 在Websphere AppServer 5.1中配置数据源
- 在 WebSphere® Studio 中配置数据源
- 在Tomcat中配制JNDI数据源
- 在Tomcat 6 中配置JNDI数据源
- 在jsp中进行JNDI数据源调试
- 有这样一个包你会买吗?
- Mysql 游标应用
- Coby推出了全新收音机
- Websphere6报“不推荐使用资源 jdbc/xxx 的直接 JNDI 查找”解决办法
- Mysql 示图应用
- 在websphere上一个J2EE应用中引用多个数据源JNDI的方法
- 为WIN32窗口应用程序附加控制台窗口,方便输入输出调试信息
- WEBSPHERE连接数据库测试错误Need to specify class name in environment or system property, or as an applet parameter, or in an application
- js幻灯片播放器
- Java和Eclipse中加载本地库研究
- TL-WN321G (rt73)USB无线网卡驱动在armlinux平台上的移植
- 24个常用方法有效优化ASP.NET的性能(三)
- Cognos8.3 安装及配置
- javascript技巧参考