千家信息网

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

发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,这篇文章将为大家详细讲解有关Servlet中怎么对Druid连接池进行整合,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。druid配置(druid.p
千家信息网最后更新 2025年02月02日Servlet中怎么对Druid连接池进行整合

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

druid配置(druid.properties)

#druid配置文件#驱动driverClassName=com.mysql.jdbc.Driver#urlurl=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连接池进行整合就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

0