重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

Servlet中怎么对Druid连接池进行整合

这篇文章将为大家详细讲解有关Servlet中怎么对Druid连接池进行整合,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

天柱网站建设公司成都创新互联公司,天柱网站设计制作,有大型网站制作公司丰富经验。已为天柱上1000家提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的天柱做网站的公司定做!

druid配置(druid.properties)

#druid配置文件
#驱动
driverClassName=com.MySQL.jdbc.Driver
#url
url=jdbc:mysql://127.0.0.1:3306/cms?useUnicode=true&characterEncoding=utf8&useSSL=true
#用户名
username=root
#密码
password=root
#连接池初始化大小
initialSize=10
#活动链接
maxActive=10
#最小连接数
minIdle=10
#使用的内置过滤器  若不配置 则不会统计SQL执行
filters=stat

JDBC连接池

/**
 * Druid连接池
 * @author tangpengfei
 */
public class DruidUtil {
	
	static DruidDataSource dataSource;
	
	static {
		Properties prop = new Properties();
		try {
			prop.load(DruidUtil.class.getClassLoader().getResourceAsStream("druid.properties"));
			dataSource = (DruidDataSource)DruidDataSourceFactory.createDataSource(prop);
			//dataSource.addFilters("stat,log4j,wall");
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public static Connection getConn() {
		try {
			return dataSource.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

}

web.xml配置

 
  	StatViewServlet
  	com.alibaba.druid.support.http.StatViewServlet
  	  
	  
	resetEnable  
	true  
      
      
	  
	loginUsername  
	admin  
      
      
	  
	loginPassword  
	admin  
      
  
  
  
  	StatViewServlet
  	/druid/*
  

关于Servlet中怎么对Druid连接池进行整合就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


文章标题:Servlet中怎么对Druid连接池进行整合
本文来源:http://cqcxhl.com/article/jgchii.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP