原!!tomcat7.0 配置数据库连接池 SQLServer2000
2015-09-22 20:15
429 查看
SQLServer2000所需的3个驱动jar包
msbase.jar
mssqlserver.jar
msutil.jar
放入WEB-INF lib文件夹中
1.META-INF 创建一个context.xml文件,内容如下:(我的案例项目)
<Context path="webTest" docBase="webTest"
reloadable="true" crossContext="true">
<Resource name="jdbc/webTest" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="wuyun" password="wuyun" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
url="jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=webTest"/>
</Context>
注意事项:
webTest是数据库名字,username 和password分别是数据库的用户名和密码。
driverClassName:数据库的驱动
url:数据库连接该驱动的地址
maxActive:最大激活连接数
maxIdle:最大保留连接数
maxWait:最大等待时间
2.修改项目的web.xml文件 ,添加如下内容:(在<web-app>内)
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/webTest</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
注意事项:
webTest:为数据库名字
3.测试:
要引入以下两个包:
我在调试过程中出现的问题:
DataSource ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/webTest");
The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
解决方法:调整或者添加相应的jre版本。
msbase.jar
mssqlserver.jar
msutil.jar
放入WEB-INF lib文件夹中
1.META-INF 创建一个context.xml文件,内容如下:(我的案例项目)
<Context path="webTest" docBase="webTest"
reloadable="true" crossContext="true">
<Resource name="jdbc/webTest" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="wuyun" password="wuyun" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
url="jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=webTest"/>
</Context>
注意事项:
webTest是数据库名字,username 和password分别是数据库的用户名和密码。
driverClassName:数据库的驱动
url:数据库连接该驱动的地址
maxActive:最大激活连接数
maxIdle:最大保留连接数
maxWait:最大等待时间
2.修改项目的web.xml文件 ,添加如下内容:(在<web-app>内)
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/webTest</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
注意事项:
webTest:为数据库名字
3.测试:
要引入以下两个包:
import javax.sql.*; import javax.naming.*;
package com.web1.model;
import java.sql.*;
import javax.sql.*; import javax.naming.*;
public class ConnDB {
private Connection ct=null;
public Connection getConn()
{
/*try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
ct=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=webTest","wuyun","wuyun");
System.out.println("jdbc");
}
catch (Exception ex) {
ex.printStackTrace();
}*/
//连接池配置
try {
Context initContext = new InitialContext();
DataSource ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/webTest");
ct = ds.getConnection();
System.out.println("连接池 连接成功!");
} catch (Exception e) {
e.printStackTrace();
}
return ct;
}
}
我在调试过程中出现的问题:
DataSource ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/webTest");
The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
解决方法:调整或者添加相应的jre版本。
相关文章推荐
- eclipse安装tomcat插件
- Eclipse +Tomcat+JDK那些事
- 监控Tomcat解决方案(监控应用服务器系列文章分享)
- jdk1.7 + ant1.9 + tomcat7 + nutch2.3 + solr5.3 + mysql5.6安装
- spring mvc + velocity 搭建实例程序maven版本并且使用的是tomcat容器而不是jetty(step by step)
- 关于SpringMVC+Spring+Hibernate+Tomcat内存溢出问题
- tomcat脚本启停
- tomcat/resin安装配置
- Eclipse导入外部项目无法识别为web项目并且无法在部署到tomcat下
- JavaWeb开发环境搭建Eclipse配置Tomcat
- myeclipse中tomcat 报异常总结
- Tomcat启动后加载两次servlet的问题
- Tomcat安装Windows系统服务配置
- 全面讲解Tomcat下SSL证书的配置(一)
- 用tomcat搭建web服务器
- 外网访问自己的tomcat
- java tomcat html5调试中需要关注的配置问题
- Tomcat使用-学习笔记
- 关于tomcat startup.bat启动后一闪而过的问题(转)
- Tomcat源码学习