作者 钟来

历史数据存储

不能预览此文件类型
  1 +driverClassName=com.mysql.cj.jdbc.Driver
  2 +url=jdbc:mysql://rm-wz9740un21f09iokuao.mysql.rds.aliyuncs.com:3306/liu_yu_le?useUnicode=true&characterEncoding=utf8&autoReconnect=true
  3 +username=luhui
  4 +password=Luhui586
  5 +#\u6700\u5927\u8FDE\u63A5\u6570\u91CF
  6 +maxActive=100
  7 +#\u6700\u5927\u7A7A\u95F2\u8FDE\u63A5
  8 +maxIdle=-1
  9 +#\u6700\u5C0F\u7A7A\u95F2\u8FDE\u63A5
  10 +minIdle=10
  11 +#\u8D85\u65F6\u7B49\u5F85\u65F6\u95F4\u4EE5\u6BEB\u79D2\u4E3A\u5355\u4F4D 60000\u6BEB\u79D2/1000\u7B49\u4E8E60\u79D2
  12 +maxWait=60000
  13 +#removeAbandoned: \u662F\u5426\u81EA\u52A8\u56DE\u6536\u8D85\u65F6\u8FDE\u63A5
  14 +removeAbandoned=true
  15 +#removeAbandonedTimeout: \u8D85\u65F6\u65F6\u95F4(\u4EE5\u79D2\u6570\u4E3A\u5355\u4F4D)
  16 +removeAbandonedTimeout=120
  17 +testOnBorrow=false
  18 +logAbandoned=true
  1 +package com.zhonglai.luhui.data.file.service.service;
  2 +
  3 +import com.zhonglai.db.DBFactory;
  4 +import org.apache.commons.dbcp.BasicDataSourceFactory;
  5 +import org.apache.commons.dbutils.QueryRunner;
  6 +
  7 +import javax.sql.DataSource;
  8 +import java.io.FileInputStream;
  9 +import java.sql.Connection;
  10 +import java.sql.SQLException;
  11 +import java.util.Properties;
  12 +
  13 +public class DataDBFactoryImp implements DBFactory {
  14 + private static DataSource ds = null;
  15 + private static QueryRunner runner;
  16 +
  17 + public DataDBFactoryImp() {
  18 + }
  19 +
  20 + public static Connection getConnection() {
  21 + try {
  22 + return ds.getConnection();
  23 + } catch (SQLException var1) {
  24 + var1.printStackTrace();
  25 + return null;
  26 + }
  27 + }
  28 +
  29 + public DataSource getDataSource() {
  30 + return ds;
  31 + }
  32 +
  33 + public QueryRunner getQueryRunner() {
  34 + return runner;
  35 + }
  36 +
  37 + static {
  38 + try {
  39 + if (null == ds) {
  40 + String path = System.getProperty("user.dir") + "/configs/";
  41 + Properties p = new Properties();
  42 + p.load(new FileInputStream(path + "sensor_dbcpconfig.properties"));
  43 + ds = BasicDataSourceFactory.createDataSource(p);
  44 + }
  45 + } catch (Exception var2) {
  46 + var2.printStackTrace();
  47 + }
  48 +
  49 + if (null == runner) {
  50 + runner = new QueryRunner(ds);
  51 + }
  52 +
  53 + }
  54 +}
  1 +package com.zhonglai.luhui.data.file.service.service;
  2 +
  3 +import com.zhonglai.dao.BaseDao;
  4 +
  5 +/**
  6 + * 数据服务
  7 + */
  8 +public class DataService {
  9 + private static BaseDao baseDao = new BaseDao(new DataDBFactoryImp());
  10 +}