tomcat5.5下JDNI的配置

拿mysql数据库和tomcat5.5为例子:
安装tomcat5.5(注意这点)
安装mysql
拷贝mysql驱动到tomcat_home/common/lib下
新建一个web工程jndi
在工程中加入index.jsp
HTML code
 
  

<% @page import = " java.util.*,javax.naming.*,java.sql.*,javax.sql.* " %>
<% @page contentType = " text/html;charset=BIG5 " %>
<%
Context ctx
= new InitialContext();
String strLookup = " java:comp/env/jdbc/test " ;
DataSource ds
= (DataSource) ctx.lookup(strLookup);
Connection con
= ds.getConnection();
if (con ! = null ){
out.print(
" success " );
}
else {
out.print(
" failure " );
}
%>

在web.xml中加入
XML code
 
  

< resource-ref >
< res-ref-name > jdbc/test </ res-ref-name >
< res-type > javax.sql.DataSource </ res-type >
< res-auth > Container </ res-auth >
< res-sharing-scope > Shareable </ res-sharing-scope >
</ resource-ref >

在tomcat_home/conf/localhost/下建立一个xml文件,文件名是 <yourAppName> .xml
例如我的工程名叫jndi,对应的名字叫jdni.xml
内容如下:
XML code
 
  

< Context >
< Resource
name ="jdbc/test"
type
="javax.sql.DataSource"
password
="bb"
driverClassName
="com.mysql.jdbc.Driver"
maxIdle
="2"
maxWait
="50"
username
="root"
url
="jdbc:mysql://localhost:3306/test"
maxActive
="4" />
</ Context >

运行测试:
打开ie,输入http://localhost:8080/jndi/index.jsp
看到success 代表配置成功 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值