Druid数据库连接池就这么简单

介绍Druid连接池 Druid连接池是阿里巴巴开源的一款基于JDBC规范的高性能连接池。它支持MySQL, PostgreSQL, Oracle, DB2, Microsoft SQL Server等数据库,而且Druid提供了监控功能,可以监控连接池的状态。下面将详细介绍Druid连接池的使用及其特点。 阅读详情

前言

本章节主要讲解Druid数据库连接池,为什么要学Druid数据库连接池呢??

我的知识储备数据库连接池有两种->C3P0,DBCP,可是现在看起来并不够用阿~当时学习C3P0的时候,觉得这个数据库连接池是挺强大的。看过的一些书上也是多数介绍了这两种数据库连接池,自己做的Demo也是使用C3P0。可是现在看起来这两种都不够了~业界发展得真快呀

上面的我就没有打码了,都是一些热心的开发者评论,正因为他们的评论才促使我会去学更好的东西,也希望大家多多指点~

于是乎,我就花一点时间去学习Druid数据库连接池了…如果有错的地方往指正~~

Druid数据库连接池是阿里的,因此文档是有中文版本的,英语不好学起来也不用那么头疼.

一、Druid介绍

Druid一般的用处有两个:

  • 替代C3P0、DBCP数据库连接池(因为它的性能更好)
  • 自带监控页面,实时监控应用的连接池情况

所以本文主要是使用Druid作为数据库连接池并且使用一下实时监控应用,做个入门学习~

二、搭建Druid环境

由于简化配置,我就直接实用SpringBoot和SpringData JPA的方式来搭建一个Druid的Demo了~~~

2.1引入pom



<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>


    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>1.1.5</version>
    </dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.2.3</version>
        <scope>test</scope>
    </dependency>
</dependencies>

2.2Druid默认的配置

配置数据源的信息(Druid),和JPA相关配置~


# 数据库访问配置
# 主数据源,默认的
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/druid
spring.datasource.username=root
spring.datasource.password=root

# 下面为连接池的补充设置,应用到上面所有数据源中
# 初始化大小,最小,最大
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
# 配置获取连接等待超时的时间
spring.datasource.maxWait=60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
spring.datasource.timeBetweenEvictionRunsMillis=60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
# 打开PSCache,并且指定每个连接上PSCache的大小
spring.datasource.poolPreparedStatements=true
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
spring.datasource.filters=stat,wall,log4j
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
# 合并多个DruidDataSource的监控数据
#spring.datasource.useGlobalDataSourceStat=true


#JPA配置
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jackson.serialization.indent_output=true

更多的配置要去看官方文档了~不过这里一般就够用了。

2.3配置监控页面

Druid的监控统计功能是通过filter-chain扩展实现,如果你要打开监控统计功能,配置StatFilter

配置druid数据源状态监控,配置一个拦截器和一个Servlet即可~


package com.example.demo;

/**
 * Created by ozc on 2018/3/26.
 *
 * @author ozc
 * @version 1.0
 */

import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * druid 配置.
 * <p>
 * 这样的方式不需要添加注解:@ServletComponentScan
 *
 * @author Administrator
 */
@Configuration
public class DruidConfiguration {

    /**
     * 注册一个StatViewServlet
     *
     * @return
     */
    @Bean
    public ServletRegistrationBean DruidStatViewServle2() {
        //org.springframework.boot.context.embedded.ServletRegistrationBean提供类的进行注册.
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");

        //添加初始化参数:initParams

        //白名单:
        servletRegistrationBean.addInitParameter("allow", "127.0.0.1");
        //IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not permitted to view this page.
        servletRegistrationBean.addInitParameter("deny", "192.168.1.73");
        //登录查看信息的账号密码.
        servletRegistrationBean.addInitParameter("loginUsername", "admin2");
        servletRegistrationBean.addInitParameter("loginPassword", "123456");
        //是否能够重置数据.
        servletRegistrationBean.addInitParameter("resetEnable", "false");
        return servletRegistrationBean;
    }

    /**
     * 注册一个:filterRegistrationBean
     *
     * @return
     */
    @Bean
    public FilterRegistrationBean druidStatFilter2() {

        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());

        //添加过滤规则.
        filterRegistrationBean.addUrlPatterns("/*");

        //添加不需要忽略的格式信息.
        filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
        return filterRegistrationBean;
    }

}

2.4JPA测试

POJO:


@Entity
public class User implements Serializable {

    /**
     * serialVersionUID.
     */
    private static final long serialVersionUID = 1L;

    /**
     * 主键.
     */
    @Id
    @GeneratedValue
    private String id;

    /**
     * 用户名.
     */
    private String userName = "";

    /**
     * 手机号码.
     */
    private String mobileNo = "";

    /**
     * 邮箱.
     */
    private String email = "";

    /**
     * 密码.
     */
    private String password = "";

    /**
     * 用户类型.
     */
    private Integer userType = 0;

    /**
     * 注册时间.
     */
    private Date registerTime = new Date();

    /**
     * 所在区域.
     */
    private String region = "";

    /**
     * 是否有效 0 有效 1 无效.
     */
    private Integer validity = 0;

    /**
     * 头像.
     */
    private String headPortrait = "";
}

Controller:


@RestController
public class UserController {

    @Autowired
    private UserRepos userRepos;

    @RequestMapping(value="saveUser")
    public User saveUser(){
        return userRepos.save(new User());
    }

    @RequestMapping(value="/findByUserName")
    public List<User> findByUserName(String userName){
        return userRepos.findByUserName(userName);
    }

    @RequestMapping(value="findByUserNameLike")
    public List<User> findByUserNameLkie(String userName){
        return userRepos.findByUserNameLike(userName);
    }

    @RequestMapping(value="findByPage")
    public Page<User> findByPage(Integer userType){
        return userRepos.findByUserType(userType, new PageRequest(1, 5));
    }



}

Repository:


public interface UserRepos extends JpaRepository<User, String> {

    /**
     * 通过用户名相等查询
     *
     * @param userName 用户名
     * @return
     */
    List<User> findByUserName(String userName);

    /**
     * 通过名字like查询
     *
     * @param userName 用户名
     * @return
     */
    List<User> findByUserNameLike(String userName);

    /**
     * 通过用户名和手机号码查询
     *
     * @param userName 用户名
     * @param mobileNo 手机号码
     * @return
     */
    User findByUserNameAndMobileNo(String userName, String mobileNo);

    /**
     * 根据用户类型,分页查询
     *
     * @param userType 用户类型
     * @param pageable
     * @return
     */
    Page<User> findByUserType(Integer userType, Pageable pageable);

    /**
     * 根据用户名,排序查询
     *
     * @param userName 用户名
     * @param sort
     * @return
     */
    List<User> findByUserName(String userName, Sort sort);

}

在页面上访问:http://localhost:8080/findByUserName?userName=Java3y

结果:

三、最后

本文只是简单的对Druid进行入门,Druid是一个非常好的开源数据库连接池框架,更多的资料可看GitHub的文档。

参考资料:

如果文章有错的地方欢迎指正,大家互相交流。习惯在微信看技术文章,想要获取更多的Java资源的同学,可以关注微信公众号:Java3y

数据库连接池的简单使用(c3p0, dbcp, Druid) 数据库连接池的简单使用--c3p0, dbcp, DruidC3P0的简单使用使用步骤1.导入jar包2.硬编码方式使用C3P03.使用配置文件方式使用C3P04. C3P0_JDBCUtils 工具类5. c3p0-config.xml 配置文件放置问题DBCP的简单使用1.导入jar包2.硬编码方式使用DBCP3.配置文件方式使用DBCP4.DBCP 连接池工具类 C3P0的简单使用 使用步骤 1.导入jar包 在工程下新建libs文件夹–>File–>Project Structure–& 阅读详情

相关推荐

深入理解数据库连接池Druid及其配置教程

本文还有配套的精品资源,点击获取 简介:数据库连接池是优化数据库交互和提高系统性能的重要组件。本文将深入探讨流行的Java连接池Druid,特别关注其1.1.21版本以及配置文件 druid.properties 的使用。Druid不仅提供连接池管理,还集成了监控、SQL解析、日志记录等附加功能。文章详细介绍了连接池的工作原理,Druid的特性,以及如何配置 ...

weixin_35995661的博客 7547

数据库连接池(Druid(德鲁伊))

当应用程序向连接池请求的连接数超过最大连 接数量时,这些请求将被加入到等待队列中。数据库连接建立一个“缓冲池”。预先在缓冲池中放入一定数量的连接,

一个菜鸡的博客 2万+

分支界定法(branch and bound)与背包问题的代码实现

分支界定法(branch and bound)与背包问题的代码实现 LastEditTime: - 2021.2.3 不卖茶的吴龙茗茶 分支界定法是一种在整数规划中常用的算法,其主要思想为将大问题分割成小问题进行求解。分支界定法是围绕着一个二叉树进行的,以背包问题为例: 假设小明有一个背包,其总的容积为30,小明有三件东西可以带,三件东西的体积分别为:10,15,20。求问小明如何能够在背包中装下更大体积的物品? .

小吴同学的小屋 1885

数据库连接池-简介&Druid使用

此处注意”test“为数据库名称,用时注意修改成自己相应的数据库名称;小技巧:注意路径这边可以先注释其他代码,直接打印,来查看当前文件路径。我这边遇到过的问题是如果你使用的SQL是8.0以上的话需要使用。​ 最后运行即可,成功连接,打印出JDBC的连接对象,结果如图。我们在文件中打开后,只选取后面的路径,即相对路径如下即可。此处我选择在与我druid同一个文件目录下创建配置文件。导入jar包 druid-1.1.12.jar。如果使用的SQL是8.0以下则使用。Druid(德鲁伊)获取数据库连接池对象。

BinCund的博客 3589

YOLOv8的Anchor-Free革新:从中心点预测到动态IoU匹配的全面解析

本文深入解析了YOLOv8采用Anchor-Free(无锚框)设计的核心优势与实现机制。通过摒弃预设锚框,模型直接预测目标中心点与宽高,结合解耦头、动态IoU匹配及Varifocal Loss等创新,显著简化了训练流程并提升了检测精度,尤其在小目标检测和模型泛化能力上表现突出。

weixin_29094301的博客 356

智能驾驶感知模块的测试评估方法(上)

对于智能驾驶系统而言,感知模块是开发难度最大、投入资源最多的核心部分。在智能驾驶开发团队内部,感知模块需要独立进行评测才能及早发现潜在缺陷或判断性能是否有改进。随着近几年BEV、OCC、E2E等新技术方案被越来越多企业应用,感知的评测变得越来越艰难,效率也变得越来越低下。本文作者基于在智驾测试行业多年经验,试图总结感知评测的基本规律和效率提升方法,以供读者一些启发。

vincent_321的博客 2559

6.13-C3p0连接池配置,DBUtils使用

DBCP连接池 一、C3p0连接池配置 开源的JDBC连接池 使用连接池的好处: 减轻数据库服务器压力 数据源: ComboPooledDataSource ComboPooledDataSource cpds = new ComboPooledDataSource(); 将数据库配置信息写在 ...

weixin_30778805的博客 367

Eureka自我保护机制

Eureka自我保护机制 默认情况下,当eureka server在一定时间内没有收到实例的心跳,便会把该实例从注册表中删除(默认是90秒),但是,如果短时间内丢失大量的实例心跳,便会触发eureka server的自我保护机制,比如在开发测试时,需要频繁地重启微服务实例,但是我们很少会把eureka server一起重启(因为在开发过程中不会修改eureka注册中心),当一分钟内收到的心跳数大量减少时,会触发该保护机制。可以在eureka管理界面看到Renews threshold和Renews(last

Soul_Ming的博客 543

Druid数据库连接池简单使用介绍

Druid数据库连接池简单使用介绍          简单使用介绍:     Druid与其他数据库连接池使用方法基本一样(与DBCP非常相似),将数据库的连接信息全部配置给DataSource对象。     下面给出2种配置方法实例:    1. 纯Java代码创建 dataSource = new DruidDataSource(); dataSource.set

程序猿开发日志【学习永无止境】 815

ModbusRTU串口读写报文解析

解析MODBUS报文的格式,讨论异常状态、读多个寄存器与写多个寄存器

Serendipitor的博客 9209

LVGL多线程编程避坑指南:从音乐播放器项目看UI与后台任务如何安全协作

本文深入探讨LVGL在多线程环境下的安全协作问题,以音乐播放器项目为例,解析UI与后台任务(如mplayer音频播放器)的典型冲突场景。提供全局互斥锁规范、任务队列异步处理等核心策略,并分享mplayer进程集成方案与进度条优化技巧,帮助开发者规避界面卡顿、内存损坏等常见问题。

weixin_42531494的博客 131

c3p0和druid数据库连接池的简单和应用

首先需要导入c3p0架包:c3p0-0.9.5.5.jar mchange-commoms-java-0.2.19.jar(你也可以使用其他版本) 导入jdbc架包:mysql-connector-java-5.1.47-bin.jar 在src下添加c3p0的配置文件名字为 c3p0-config.xml,具体配置内容如下(简单配置,更多参数配置可参考互联网): <c3p0-config> <default-config> <!--连接参数--> <proper

qq_45193057的博客 228

物联网与人工智能项目实战:构建智能农业监控系统

智能农业监控系统通过物联网技术实时监测农业环境中的各项数据(如土壤湿度、温度、光照强度等),并利用人工智能技术分析和预测农业生产的趋势,进而为农民提供决策支持。系统的核心目标是提高农作物的产量和品质,同时减少资源浪费,优化农田管理。环境监测:实时采集农田的温湿度、土壤湿度、光照等环境数据。作物生长监测:通过传感器和图像识别技术监测作物的生长状况。智能灌溉系统:根据土壤湿度和气候条件自动调整灌溉量。病虫害检测与预警:利用人工智能和图像识别技术自动检测作物病虫害,并及时给出预警。数据分析与决策支持。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 709

简单的登录注册(前端+后端+MySQL数据库 DRuid连接池 DBUtils)

简单的登录注册(前端+后端+MySQL数据库 DRuid连接池 DBUtils) 文章目录简单的登录注册(前端+后端+MySQL数据库 DRuid连接池 DBUtils)结果图前端代码后端代码工具Utils代码User类代码 结果图 前端代码 登录页面 <%-- Created by IntelliJ IDEA. User: yllch Date: 2020/10/20 Time: 16:42 To change this template use File | Se

cx9977的博客 2908

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Druid数据库连接池的简单介绍和使用

Druid 是阿里巴巴开源平台上一个数据库连接池实现,结合了 C3P0、DBCP 等 DB 池的优点,同时加入 了日志监控。 Druid 可以很好的监控 DB 池连接和 SQL 的执行情况,天生就是针对监控而生的 DB 连接池。

0 1800

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

mysql druid使用_数据库连接池 —— Druid的简单使用

Druid不仅是一个数据库连接池,还包含一个ProxyDriver、一系列内置的JDBC组件库、一个SQL Parser。支持所有JDBC兼容的数据库,包括Oracle、MySql、Derby、Postgresql、SQL Server、H2等。使用步骤一定要导入jar架包。要配置好文件,如果不配置文件,记得在程序中自行添加。导入jar包: druid-1.0.9.jar、mysql-connec...

weixin_39730801的博客 1051

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

Druid数据库连接池简单工具类

//声明先得下载Druid包 http://central.maven.org/maven2/com/alibaba/druid/1.1.9/ 还得有数据库的驱动包 //自己写druid.properties配置 package com.JdbcUtli.druid; import java.io.IOException; import java.sql.*; import java...

大风起兮云飞扬 529

Druid数据库连接池

Druid是阿里巴巴开源平台上一个数据库连接池实现,它结合了C3P0、DBCP、Proxool等DB池的优点,同时加入了日志监控,可以很好的监控DB池连接和SQL的执行情况,可以说是针对监控而生的DB连接池,可以说是目前最好的连接池之一。 import java.sql.Connection; import java.util.Properties; import javax.sql.DataSource; import com.alibaba.druid.pool.DruidDat...

qq_42530693的博客 406

Java学习(数据库连接池(C3P0,Druid),Spring框架对JDBC的简单封装)

2022/2/29 一、数据库连接池 1.概念:其实就是一个容器(集合),存放数据库连接的容器. 当系统初始化好后,容器被创建,容器中会申请一些连接对象,当用户来访问数据库时,从容器中获取连接对象,用户访问完后,会将连接对象归还给容器。 2.好处:节省资源,还可以使用户访问高效 3.实现: 1)标准接口:DataSource javax.sql包下的 1.1方法: ...

XXX_17的博客 362

简单的Druid数据库连接池的使用

首先创建一个 druid.properties 配置文件 driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql:///mydb // mydb 为你的数据库名 username=root //你的用户名 password=root //你的密码 initialSize=5 maxActive=10 maxWait=3000 之后新建utils工具类包 创建JDBCUtils.java import com.alibaba.druid.p

MissJxs的博客 282
上一篇: Druid数据库连接池就是这么简单
下一篇: 八大基础排序总结
Java3y
Java3y 领域专家: 后端开发技术领域 领域专家: 后端开发技术领域
博客等级 码龄9年 1万+粉丝 509原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值