Websphere6报“不推荐使用资源 jdbc/xxx 的直接 JNDI 查找”解决办法

1.在WEB-INF下新建文件ibm-web-bnd.xmi(里面包括JNDI的引用就是在WEBSPHERE里配置的数据源名称里的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_1216699055547" jndiName="CIS_DS">
<bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1216699055547"/>
</resRefBindings>
</com.ibm.ejs.models.base.bindings.webappbnd:WebAppBinding>
2.在WEB-INF下的web.xml文件中添加对jndi的引用(res-ref-name名称一般跟数据源名称相同名CIS_DS)
<resource-ref id="ResourceRef_1216699055547">
<description></description>
<res-ref-name>CIS_DS</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.在代码中使用java:comp/env/CIS_DS(因为在web.xml文件里把JNDI已经映射为CIS_DS,所以就可以用java:comp/env/CIS_DS访问)就可以连接数据库
Context ctx = new InitialContext();
Object obj = ctx.lookup("java:comp/env/CIS_DS");
ds = (DataSource) obj;
conn = ds.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from c_jgb where rownum<10");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值