Tomcat6.0+mysql+jdk1.6.0 jndi连接池的配置步骤

<script>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>

1. jdk,tomcat的环境配置好,不要忘记tomcat的环境变量配置

2. 使用myeclipse开发,配置好服务器

3. 新建一个web工程,首先将mysql-connector-java-5.0.8-bin.jar拷贝到Web-inf/lib/,并将这个jar包拷贝到Tomcat_Home/lib/,否则提示找不到驱动

4. xml文件

l 在工程下META-INF/新建一个context .xml

<?xml version="1.0" encoding="UTF-8"?>

<Context>

<Resource auth="Container"

driverClassName="com.mysql.jdbc.Driver"

maxActive="100"

maxIdle="30"

maxWait="10000"

name="jdbc/fck"

username="root"

password="root"

type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/fcktest?characterEncoding=UTF-8" />

</Context>

l Web.xml

<resource-ref>

<res-ref-name>jdbc/fck</res-ref-name>

res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>

5. index.jsp进行测试

<%@ page language="java" import="java.util.*,javax.naming.*,java.sql.*,javax.sql.*" pageEncoding="UTF-8"%>

<%

Context ctx = new InitialContext();

String strLookup = "java:comp/env/jdbc/fck";

DataSource ds =(DataSource) ctx.lookup(strLookup);

Connection con = ds.getConnection();

if (con != null){

out.print("success");

}else{

out.print("failure");

}

%>

你可能感兴趣的:(java,sql,tomcat,mysql,jdbc)