JFinal中,使用c3p0多数据源进行配置,在覆盖的的方法“public void configPlugin(Plugins me) ”中实现。

    下面是mysql和oracle多数据源的配置代码,一定要注意两种数据库连接串的区别。

            C3p0Plugin dsMysql = new C3p0Plugin("jdbc:mysql://xxx.xxx.xx.xx/数据库名?zeroDateTimeBehavior=convertToNull","用户名", "密码");
    		me.add(dsMysql);
    		ActiveRecordPlugin arpMysql = new ActiveRecordPlugin("mysql", dsMysql);
    		me.add(arpMysql);
    		arpMysql.addMapping("agent", Agent.class);
    		arpMysql.addMapping("team", Team.class);
    		arpMysql.addMapping("sys_jgxx", "jgbm", Sysjgxx.class);
    		arpMysql.addMapping("acr", Acr.class);
    		arpMysql.addMapping("r_agent_team", R_agent_team.class);
    		arpMysql.addMapping("queuepool", Queuepool.class);
    		arpMysql.addMapping("cdr", Cdr.class);
    		arpMysql.addMapping("menu", Menu.class);
    		C3p0Plugin dsOracle = new C3p0Plugin("jdbc:oracle:thin:@xxx.xxx.xx.xx:1521:SID", "用户名","密码");
    		dsOracle.setDriverClass("oracle.jdbc.driver.OracleDriver");
    		me.add(dsOracle);
    		ActiveRecordPlugin arpOracle = new ActiveRecordPlugin("oracle",dsOracle);
    		me.add(arpOracle);
    		arpOracle.setDialect(new OracleDialect());
    		// 配置属性名(字段名)大小写不敏感容器工厂
    		arpOracle.setContainerFactory(new CaseInsensitiveContainerFactory());
    		arpOracle.addMapping("TB_CPU_PERF", Ora_Cpu.class);
    		arpOracle.addMapping("tb_comp_perf", Ora_Comp.class);
    		arpOracle.addMapping("tb_disk_perf", Ora_Disk.class);
    		arpOracle.addMapping("tb_nic_perf", Ora_Nic.class);

    本文为风林火山博客原创,转载请注明出处:www.flcoder.com