jfinal 使用C3p0同时配置mySql与Oracle数据库
/**
* 配置插件
*/
public void configPlugin(Plugins me) {
//// // 配置C3p0数据库连接池插件
C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
c3p0Plugin.setDriverClass(PropKit.get("driverClassName"));
me.add(c3p0Plugin);
// 配置ActiveRecord插件
ActiveRecordPlugin arp = new ActiveRecordPlugin("mysql",c3p0Plugin);
me.add(arp);
// 所有配置在 MappingKit 中搞定
_MappingKit.mapping(arp);
//添加oracle数据源
C3p0Plugin oraclePlugin = new C3p0Plugin(PropKit.get("ojdbc.url"), PropKit.get("ojdbc.username"), PropKit.get("ojdbc.password").trim());
oraclePlugin.setDriverClass(PropKit.get("ojdbc.driverClassName"));
me.add(oraclePlugin);
// 配置ActiveRecord插件
ActiveRecordPlugin arpOracle = new ActiveRecordPlugin("oracle",oraclePlugin);
me.add(arpOracle);
// 配置Oracle方言
arpOracle.setDialect(new OracleDialect());
// 配置属性名(字段名)大小写不敏感容器工厂
arpOracle.setContainerFactory(new CaseInsensitiveContainerFactory());
// 所有配置在 MappingKit 中搞定
arpOracle.addMapping("T_TOU_TRAVEL", "F_ID",T_tour_travel.class);
arpOracle.addMapping("G_BASICINFO", "DYKH",G_basicinfo.class);
// _MappingKitOra.mapping(arpOracle);
// 缓存
me.add(new EhCachePlugin());
}
配置文件:
jdbcUrl = jdbc:mysql://172.16.19.162/tour?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
database = tour
user = root
password =sdta12345
devMode = true
driverClassName=com.mysql.jdbc.Driver
##oracle
ojdbc.driverClassName=oracle.jdbc.driver.OracleDriver
ojdbc.url=jdbc:oracle:thin:@172.16.19.152:1521:orcl
ojdbc.username=yes_user
ojdbc.password=yes_2017
ojdbc.showsql=true
本文原创,转载必追究版权。