zoukankan      html  css  js  c++  java
  • Java c3p0连接池之二

    <?xml version="1.0" encoding="UTF-8"?>
    
    <!-- c3p0-config.xml文件配置 -->
    
    <c3p0-config>
        <named-config name="bookstore_c3p0">
            <!-- 基本配置 -->
            <property name="user">LF</property>
            <property name="password">LF</property>
            <property name="jdbcUrl">jdbc:oracle:thin:@192.168.10.105:1521:orcl</property>
            <property name="driverClass">oracle.jdbc.driver.OracleDriver</property>
            <!-- 配置初始值 -->
            <property name="initialPoolSize">16</property>
            <property name="maxPoolSize">25</property>
            <property name="minPoolSize">10</property>
        </named-config>
    </c3p0-config>
    package com.lf.bookstore.utils;
    
    
    import java.sql.Connection;
    import java.sql.SQLException;
    
    import javax.sql.DataSource;
    
    import com.mchange.v2.c3p0.ComboPooledDataSource;
    
    public class JdbcUtils {
        public static void main(String[] args) {
            
            System.out.println(JdbcUtils.getConnection());
        }
    
        /**
         * 获取数据库连接
         * @return
         */
        public static Connection getConnection() {
            DataSource ds = new ComboPooledDataSource("bookstore_c3p0");
            Connection connection = null;
            try {
                connection = ds.getConnection();
                return connection;
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return null;
        }
    }
  • 相关阅读:
    linux 系统管理(2) 文件或目录数量统计
    linux系统管理(1)之 内核编译选项查看
    apt 命令大全
    system命令
    ubuntu 登陆闪回
    网络知识之ipset
    mac 系统配置(一)
    windows下的qt编译器配置
    QT5.14.1+qwt-6.1.4编译
    无法打开源文件QtWidgets/QApplication
  • 原文地址:https://www.cnblogs.com/lantu1989/p/6227222.html
Copyright © 2011-2022 走看看