package com.ruoyi.web.Utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.beans.PropertyVetoException;
import java.sql.Connection;

/**
 * 物流系统数据库操作
 *
 * @author Administrator
 *
 */
public class DataDBUtils {
	private static DataSource ds;

	static {
		ComboPooledDataSource cpds = null;
		try {
			cpds = new ComboPooledDataSource();
			cpds.setCheckoutTimeout(30000);
			cpds.setIdleConnectionTestPeriod(30);
			cpds.setInitialPoolSize(10);
			cpds.setMaxIdleTime(30);//
			cpds.setMaxPoolSize(30);
			cpds.setMaxStatementsPerConnection(100);
			cpds.setMinPoolSize(5);
			cpds.setMaxStatements(75);
			cpds.setAcquireIncrement(3);
			cpds.setNumHelperThreads(3);
			cpds.setDriverClass("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			cpds.setJdbcUrl("jdbc:sqlserver://192.168.9.99:1433;DatabaseName=jn_quot");
			cpds.setUser("sa");
			cpds.setPassword("Itcenter110-");
			ds = cpds;
		} catch (PropertyVetoException e) {
			System.out.println("与SqlServer数据库连接失败！");
		}
	}

	private DataDBUtils() {

	}

	public static DataSource getDatasSource() {
		return ds;
	}

	public static Connection getConnection() {
		Connection con = null;
		try {
			con = ds.getConnection();// 每一次从ds中获取一个新的连接
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;
	}
}
