DemoConfig.java
/**
* 多数据源
*/
public final void configOtherDB(Plugins me) {
// 读取数据库配置
loadPropertyFile("config/otherdbs.properties");
if(getProperty("dbsources").equals("")) return;
String dbsource = getProperty("dbsources");
DruidPlugin dp = new DruidPlugin(getProperty(dbsource + ".jdbcUrl"),getProperty(dbsource + ".user"),
getProperty(dbsource + ".password"));
dp.setDriverClass(getProperty(dbsource + ".driverClass"));
dp.addFilter(new StatFilter());
dp.setMaxActive(getPropertyToInt(dbsource + ".dbMaxActive"));
if (RapidConsts.isIS_DEV_MODE()) {
dp.setInitialSize(1);
} else {
dp.setInitialSize(getPropertyToInt(dbsource + ".dbInitSize"));
}
WallFilter wall = new WallFilter();
wall.setDbType(getProperty(dbsource + ".dbType"));
dp.addFilter(wall);
me.add(dp);
// 配置数据库操作工具
int dbToll = configDbTool();
RapidConsts.setCURRENT_DB_TOOL(dbToll);
switch (dbToll) {
case RapidConsts.DB_TOOL_ACTIVERECORD:
// 配置ActiveRecord插件
ActiveRecordPlugin arp = new ActiveRecordPlugin(dbsource, dp);
me.add(arp);
arp.setDialect(new OracleDialect());
arp.setShowSql(RapidConsts.isIS_DEV_MODE());
break;
case RapidConsts.DB_TOOL_MYBATIS:
MyBatisPlugin myBatisPlugin = new MyBatisPlugin(dbsource, dp);
me.add(myBatisPlugin);
myBatisPlugin.setShowSql(RapidConsts.isIS_DEV_MODE());
break;
}
}#dbsources 使用逗号分隔的数据源id,数量必须跟下边明细配置的总记录一致 不能使用druid 对于mysql数据库,必须保证dbsource与dbname的名称一致
dbsources = sxts
#zhs
sxts_zhsbpt.driver = oracle.jdbc.driver.OracleDriver
sxts_zhsbpt.jdbcUrl = jdbc:oracle:thin:@192.71.187:1521:orcl
sxts_zhsbpt.user = SXTS
sxts_zhsbpt.password = 1357g
sxts_zhsbpt.dbType = oracle
sxts_zhsbpt.dbMaxActive = 150
sxts_zhsbpt.dbInitSize = 40
web调用:
public void run() {
Bean bean = new Bean();
bean.put("currentRyxx_nsrsbh", nsrsbh);
try {
new RapidDao();// 查询conts之前 先初初始化默认dao
// 查询待同步数据
List<Bean> list = new RapidDao("dbsource").selectListByXml(
"api_sb_request_" + mainBean.getStr("dbtype")
+ "_select", mainBean);
} catch (Exception e) {
e.printStackTrace();
} finally {
new RapidDao();// 通过构造函数 初始化默认数据源
}
}预想结果: list 有值 , 测试结果: 报数据库找不到表 com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'stxt.sb_request' doesn't exist
实际 那张表在oracle中,而数据库也没自动切换
new RapidDao("dbsource")这行就找不到oracle数据源了
项目:JFinal