cyx-sync/src/main/java/com/cyx/db/Jdbc.java

57 lines
1.5 KiB
Java

package com.cyx.db;
import com.alibaba.druid.filter.config.ConfigTools;
import com.cyx.log.EventLog;
import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
/**
* @Author Created by cyx.zhang Administrator on 2023/8/25 8:49 周五
* @Description: TOTO
*/
public class Jdbc {
/**
* 加载配置文件
*/
private static Prop p = PropKit.use("config.properties");
/**
* 配置Druid数据库连接池插件
* @return
*/
public static DruidPlugin createDruidPlugin() {
DruidPlugin druidPlugin = null;
try {
String root = ConfigTools.decrypt(p.get("user"));
String pass = ConfigTools.decrypt(p.get("password"));
druidPlugin = new DruidPlugin(p.get("jdbcUrl"),root,pass,p.get("driver"));
} catch (Exception e) {
e.printStackTrace();
}
return druidPlugin;
}
public static String jdbc(){
String is = "1";
try {
//创建druid连接池
DruidPlugin druidPlugin = createDruidPlugin();
//最大并发连接数
druidPlugin.setMaxActive(150);
//初始化连接数量
druidPlugin.setInitialSize(25);
//最小空闲连接数
druidPlugin.setMinIdle(15);
ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
druidPlugin.start();
arp.start();
}catch (Exception e){
is = "0";
EventLog.error("异常:"+e.getMessage());
}
return is;
}
}