package com.jdbc.utils;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

public class JDBCDruid {

    private static DataSource data;
    static{
        Properties ps=new Properties();
        try {
            ps.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("druid.properties"));
            data=DruidDataSourceFactory.createDataSource(ps);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {
        return data.getConnection();
    }
    public static DataSource getDataSource(){
        return data;
    }


}

 

druid.properties 配置文件

driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/mybase
username=root
password=root
initialSize=5
maxActive=10
maxWait=3000
minIdle=3


相关文章:

  • 2021-08-12
  • 2021-11-22
  • 2021-12-24
  • 2022-03-08
  • 2021-11-27
  • 2021-08-28
  • 2022-01-07
  • 2022-01-07
猜你喜欢
  • 2022-01-08
  • 2021-09-21
  • 2021-09-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-26
相关资源
相似解决方案