Light  Rain serena

«September 2025»
123456
78910111213
14151617181920
21222324252627
282930


公告

期待

超级好友 Rachel


我的分类(专题)

首页(262)
知识积累(40)
乐瑟温柔(108)
经验杂谈(20)
良辰吉日(2)
杂七杂八(57)
天景共赏(10)
感触文字(23)


最新日志
sunshine girl
过云雨
summer whisper
边走边唱
岛歌
不必在乎我是谁
如果有来生
Fing Fing 下
大明宫
我没有魅力

最新回复
回复:边界类、控制类、实体类
回复:边界类、控制类、实体类
回复:边界类、控制类、实体类
回复:《极地特快》插曲《When Chr
回复:边界类、控制类、实体类
回复:不必在乎我是谁
回复:边界类、控制类、实体类
回复:如果有来生
回复:Fing Fing 下
回复:我没有魅力

留言板
签写新留言

老大&老师,我想你.....
好文好多阿
886电台 好听
cai
您的子域名已开通
hi
祝福
祝福

你好

统计
blog名称:小雨
日志总数:262
评论数量:1273
留言数量:15
访问次数:4677834
建立时间:2005年1月8日

链接

有事?
音乐,永不厌倦
宁静的心情驿站
我的声音
TIPOblog
tipo bbs
appleVB
网页设计
英语学习2
英语学习3
FLASH
网络书籍
网络电台



我的博客朋友
最有技术的blog
xenium
花差花差
瓜少
span
a lai
琦少
陈少
v
阿当
http://www.ypb.cc/
痞子若鱼
另一个同行
年轻人bcims

 




W3CHINA Blog首页    管理页面    写新日志    退出

[经验杂谈]tomcat5.0 sqlserver2000 使用缓冲池的例子
小雨 发表于 2007/4/7 11:08:12

1 下载sqlserver2000 for jdbc sp3   2 classpath=%TOMCAT_HOME%\common\lib\msbase.jar;%TOMCAT_HOME%\common\lib\mssqlserver.jar;%TOMCAT_HOME%\common\lib\msutil.jarJAVA_HOME=C:\j2sdk1.4.2_07 TOMCAT_HOME=C:\Program Files\Apache Software Foundation\Tomcat 5.0 3 将数据库驱动的3个jar文件和 C:\j2sdk1.4.2_07\lib 下的tool.jar 文件拷贝到TOMCAT_HOME下的common\lib 下 4 通过管理界面配置数据池 500)this.width=500'> url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=northwind classname=com.microsoft.jdbc.sqlserver.SQLServerDriver 保存以后一定要提交 3 修改自己工程下的 web.xml文件,加入  <resource-ref>   <description>myjdbc</description>   <res-ref-name>myjdbc</res-ref-name>   <res-type>javax.sql.DataSource</res-type>   <res-auth>Container</res-auth>     </resource-ref> 最后类似于 <?xml version="1.0" encoding="ISO-8859-1"?><!--  Copyright 2004 The Apache Software Foundation   Licensed under the Apache License, Version 2.0 (the "License");  you may not use this file except in compliance with the License.  You may obtain a copy of the License at       http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software  distributed under the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and  limitations under the License.--> <web-app 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"    version="2.4">   <display-name>Welcome to Tomcat</display-name>  <description>     Welcome to Tomcat  </description> <!-- JSPC servlet mappings start -->   <resource-ref>   <description>myjdbc</description>   <res-ref-name>myjdbc</res-ref-name>   <res-type>javax.sql.DataSource</res-type>   <res-auth>Container</res-auth>     </resource-ref><!-- JSPC servlet mappings end --> </web-app> 接下来,在%tomcat_home%\conf\Catalina\localhost目录下建立一个与你工程名同名的xml文件。例如你的工程名是Myapp,那么你就新建一个Myapp.xml,内容如下:<?xml version="1.0" encoding="utf-8"?><Context docBase="Myapp" path="/Myapp" workDir="work\Catalina\localhost\Myapp"><ResourceLink             name="myjdbc"            global="myjdbc"            type="javax.sql.DataSource"          /></Context> 4 重新启动 tomcat 5写jsp测试 <%@ page contentType="text/html;charset=gb2312"%><%@ page import="java.sql.*"%> <%@ page import="javax.sql.*"%> <%@ page import="javax.naming.*"%> <% int i=0;Connection conn = null; Context initCtx = new InitialContext();if (initCtx == null) throw new Exception("不能获取Context!");Context ctx = (Context) initCtx.lookup("java:comp/env"); Object obj = (Object) ctx.lookup("myjdbc");//获取连接池对象 javax.sql.DataSource ds = (javax.sql.DataSource) obj; //类型转换 conn = ds.getConnection(); Statement stmt = conn.createStatement(); PreparedStatement ps=conn.prepareStatement("select * from Orders"); ResultSet rs=ps.executeQuery(); while(rs.next()){ out.println(rs.getString(1)+"<BR>"); i++; } rs.close(); stmt.close(); conn.close(); out.println("连接池测试成功"+i); %>  最后记得启动sqlserver ,否则会报无法建立连接池的错误

阅读全文(4159) | 回复(0) | 编辑 | 精华


发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)
站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.030 second(s), page refreshed 144774361 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号