Config.java
public void configPlugin(Plugins me) {
loadPropertyFile("classes/config.properties");
C3p0Plugin cp = new C3p0Plugin(getProperty("jdbc.url"), getProperty("jdbc.username"), getProperty("jdbc.password"), getProperty("jdbc.driverClassName")); //关键:使用C3P0
me.add(cp);
ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
me.add(arp);
arp.setDialect(new AnsiSqlDialect());//关键:使用AnsiSqlDialect
arp.setContainerFactory(new CaseInsensitiveContainerFactory());
}config.properties
##-------------------------------------------------
## SQL Server
##-------------------------------------------------
jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc:sqlserver://localhost:1433;DatabaseName=dbname
jdbc.username=sa
jdbc.password=123456
jdbc.dbType=sqlserver
本文介绍如何在Java应用中配置C3P0连接池和ActiveRecord插件,实现数据库操作。通过加载配置文件,初始化C3P0Plugin,并将其添加到插件管理器,再设置ActiveRecordPlugin使用C3P0连接池进行数据库交互。
954

被折叠的 条评论
为什么被折叠?



