关于tomcat中配置连接池

chencheng2240 2009-04-12 10:31:20
将sql2000与tomcat相连接,,我下载了jdbc驱动包,也安装了sql2000sp3补丁,,但是不知道后面具体怎么配置,,希望大家帮帮小弟,告之详情,,感激不尽
...全文
105 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
chencheng2240 2009-04-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wanghao1987 的回复:]
1 jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href=" <%=basePath%>">

<title>My JSP 'testds.jsp'…
[/Quote]

能说具体点吗??我是初学的啊,,准备先用一个现成的系统试运行一下,,,结果出错了,,这段代码怎么用啊???谢谢。。。。
chencheng2240 2009-04-12
  • 打赏
  • 举报
回复
能说具体点吗??我是初学的啊,,准备先用一个现成的系统试运行一下,,,结果出错了,,这段代码怎么用啊???谢谢。。。。
SystemKing 2009-04-12
  • 打赏
  • 举报
回复
dataSource.xml

<Context path="/DataSource" debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/testds" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="123456" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test" />
</Context>
---------------
url换掉
wanghao1987 2009-04-12
  • 打赏
  • 举报
回复
1 jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'testds.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<%
java.sql.Connection conn = null;
javax.naming.Context ctx = new javax.naming.InitialContext(); //得到Tomcat上下文
javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/testds");
conn = ds.getConnection(); //从连接池去数据库连接
if(!conn.isClosed())
out.println("数据库连接池配置成功");
conn.close(); //释放数据库连接[将数据库连接放回连接池]
%>
</body>
</html>


2 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<resource-ref>
<res-ref-name>jdbc/testds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>


3 dataSource.xml

<Context path="/DataSource" debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/testds" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="123456" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test" />
</Context>
zhangpeixv 2009-04-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 chencheng2240 的回复:]
能说具体点吗??我是初学的啊,,准备先用一个现成的系统试运行一下,,,结果出错了,,这段代码怎么用啊???谢谢。。。。
[/Quote]

网上例子很多的,LZ不防多看看
tomcat5和6的配置都有区别

81,111

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧