• Spring数据库连接


    1.C3P0数据库连接

    2.DBCP数据库连接

    3.Druid数据库连接

    C3P0数据库连接:

    1.先到(http://www.mvnrepository.com/)Maven网址找到C3P0的数据源依赖包

    <!-- https://mvnrepository.com/artifact/com.mchange/c3p0 -->
    <dependency>
        <groupId>com.mchange</groupId>
        <artifactId>c3p0</artifactId>
        <version>0.9.5.2</version>
    </dependency>

    2.在Spring里面进行配置信息

    <!--配置数据源-->
    <bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="com.mysql.cj.jdbc.Driver"></property> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ot?serverTimezone=GMT%2B8&amp;useSSL=false&amp;allowPublicKeyRetrieval=true"></property> <property name="user" value="root"></property> <property name="password" value="123456"></property> <property name="minPoolSize" value="3"></property> <property name="maxPoolSize" value="15"></property> <property name="initialPoolSize" value="3"></property> </bean>

    3.绑定配置数据源的id="myDataSource" 在下面的文件ref中绑定

    <bean id="mySqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="myDataSource"></property>
            <property name="mapperLocations" value="classpath*:Mapper/*.xml"></property>
        </bean>

    DBCP数据库连接:

    1.先到(http://www.mvnrepository.com/)Maven网址找到DBCP的数据源依赖包

    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-dbcp2</artifactId>
        <version>2.5.0</version>
    </dependency>

    2.在Spring里面进行配置信息

    <bean id="myDataSource-dbcp" class="org.apache.commons.dbcp2.BasicDataSource">
            <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/ot?serverTimezone=GMT%2B8&amp;useSSL=false&amp;allowPublicKeyRetrieval=true"></property>
            <property name="username" value="root"></property>
            <property name="password" value="123456"></property>
        </bean>

    3.绑定配置数据源的id="myDataSource-dbcp" 在下面的文件ref中绑定

    <bean id="mySqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="myDataSource-dbcp"></property>
            <property name="mapperLocations" value="classpath*:Mapper/*.xml"></property>
    </bean>

    Druid数据库连接:

    1.先到(http://www.mvnrepository.com/)Maven网址找到Druid的数据源依赖包

    <!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>1.1.10</version>
    </dependency>

    2.在Spring里面进行配置信息

    <bean id="Druid" class="com.alibaba.druid.pool.DruidDataSource">
            <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/ot?serverTimezone=GMT%2B8&amp;useSSL=false&amp;allowPublicKeyRetrieval=true"></property>
            <property name="username" value="root"/>
            <property name="password" value="123456"/>
        </bean>

    3.绑定配置数据源的id="Druid" 在下面的文件ref中绑定

    <bean id="mySqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="Druid"></property>
            <property name="mapperLocations" value="classpath*:Mapper/*.xml"></property>
    </bean>
    myDataSource-dbcp
  • 相关阅读:
    【.NET】VS2013创建Windows服务与调试服务
    【JS】处理数据四舍五入(tofixed与round的区别详解)
    【微信小程序】 基础语义笔记2:基本组件、获取节点信息
    面向对象和面向过程的优点和缺点
    【微信小程序】 基础语义笔记1:配置、页面文件、组件。
    【微信小程序】 wxParse组件
    zookeeper 碎片知识点
    zookeeper 基本概念
    RocketMQ 知识点
    单例模式---双层检验锁+volatile
  • 原文地址:https://www.cnblogs.com/Mr-Deng/p/9625931.html
Copyright © 2020-2023  润新知