摘自c3p0.jar,方便查看
//c3p0.properties
#
#Thisfileisdetritusfromvarioustestingattempts
#thevaluesbelowmaychange,andoftendonotrepresent
#reasonablevaluesfortheparameters.
#
#c3p0.testConnectionOnCheckout=true
#c3p0.testConnectionOnCheckin=true
#c3p0.minPoolSize=3
#c3p0.maxPoolSize=20
#c3p0.checkoutTimeout=2000
#c3p0.idleConnectionTestPeriod=5
#c3p0.maxConnectionAge=10
#c3p0.maxIdleTime=2
#c3p0.maxIdleTimeExcessConnections=1
#c3p0.propertyCycle=1
#c3p0.numHelperThreads=10
#c3p0.unreturnedConnectionTimeout=15
#c3p0.debugUnreturnedConnectionStackTraces=true
#c3p0.maxStatements=30
#c3p0.maxStatementsPerConnection=5
#c3p0.maxAdministrativeTaskTime=3
#c3p0.preferredTestQuery=SELECT1
#c3p0.preferredTestQuery=SELECTaFROMemptyyukyukWHEREa=5
#c3p0.preferredTestQuery=SELECTaFROMtestpbdsWHEREa=5
#c3p0.usesTraditionalReflectiveProxies=true
#c3p0.automaticTestTable=PoopyTestTable
#c3p0.acquireIncrement=4
#c3p0.acquireRetryDelay=1000
#c3p0.acquireRetryAttempts=60
#c3p0.connectionTesterClassName=com.mchange.v2.c3p0.test.AlwaysFailConnectionTester
#c3p0.initialPoolSize=10
c3p0.jdbcUrl=jdbc:postgresql://localhost/c3p0-test
c3p0.driverClass=org.postgresql.Driver
c3p0.user=swaldman
c3p0.password=test
#c3p0.user=poop
#c3p0.password=scoop
#com.mchange.v2.log.MLog=com.mchange.v2.log.log4j.Log4jMLog
#com.mchange.v2.log.MLog=com.mchange.v2.log.jdk14logging.Jdk14MLog
#com.mchange.v2.log.MLog=com.mchange.v2.log.FallbackMLog
#com.mchange.v2.log.NameTransformer=com.mchange.v2.log.PackageNames
#com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=ALL
#com.mchange.v2.c3p0.VMID=poop
#Thisfileisdetritusfromvarioustestingattempts
#thevaluesbelowmaychange,andoftendonotrepresent
#reasonablevaluesfortheparameters.
#
#c3p0.testConnectionOnCheckout=true
#c3p0.testConnectionOnCheckin=true
#c3p0.minPoolSize=3
#c3p0.maxPoolSize=20
#c3p0.checkoutTimeout=2000
#c3p0.idleConnectionTestPeriod=5
#c3p0.maxConnectionAge=10
#c3p0.maxIdleTime=2
#c3p0.maxIdleTimeExcessConnections=1
#c3p0.propertyCycle=1
#c3p0.numHelperThreads=10
#c3p0.unreturnedConnectionTimeout=15
#c3p0.debugUnreturnedConnectionStackTraces=true
#c3p0.maxStatements=30
#c3p0.maxStatementsPerConnection=5
#c3p0.maxAdministrativeTaskTime=3
#c3p0.preferredTestQuery=SELECT1
#c3p0.preferredTestQuery=SELECTaFROMemptyyukyukWHEREa=5
#c3p0.preferredTestQuery=SELECTaFROMtestpbdsWHEREa=5
#c3p0.usesTraditionalReflectiveProxies=true
#c3p0.automaticTestTable=PoopyTestTable
#c3p0.acquireIncrement=4
#c3p0.acquireRetryDelay=1000
#c3p0.acquireRetryAttempts=60
#c3p0.connectionTesterClassName=com.mchange.v2.c3p0.test.AlwaysFailConnectionTester
#c3p0.initialPoolSize=10
c3p0.jdbcUrl=jdbc:postgresql://localhost/c3p0-test
c3p0.driverClass=org.postgresql.Driver
c3p0.user=swaldman
c3p0.password=test
#c3p0.user=poop
#c3p0.password=scoop
#com.mchange.v2.log.MLog=com.mchange.v2.log.log4j.Log4jMLog
#com.mchange.v2.log.MLog=com.mchange.v2.log.jdk14logging.Jdk14MLog
#com.mchange.v2.log.MLog=com.mchange.v2.log.FallbackMLog
#com.mchange.v2.log.NameTransformer=com.mchange.v2.log.PackageNames
#com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=ALL
#com.mchange.v2.c3p0.VMID=poop
//c3p0-config.xml
<c3p0-config>
<default-config>
<!--<propertyname="automaticTestTable">con_test</property>-->
<!--<propertyname="checkoutTimeout">30000</property>-->
<!--<propertyname="idleConnectionTestPeriod">30</property>-->
<!--<propertyname="initialPoolSize">10</property>-->
<!--<propertyname="maxIdleTime">30</property>-->
<!--<propertyname="maxIdleTimeExcessConnections">10</property>-->
<!--<propertyname="maxConnectionAge">60</property>-->
<!--<propertyname="propertyCycle">1</property>-->
<!--<propertyname="maxPoolSize">25</property>-->
<!--<propertyname="minPoolSize">5</property>-->
<!--<propertyname="maxStatements">0</property>-->
<!--<propertyname="maxStatementsPerConnection">5</property>-->
<!--<propertyname="maxAdministrativeTaskTime">4</property>-->
<!--<propertyname="connectionCustomizerClassName">com.mchange.v2.c3p0.test.TestConnectionCustomizer</property>-->
<!--<propertyname="unreturnedConnectionTimeout">15</property>-->
<!--<propertyname="debugUnreturnedConnectionStackTraces">true</property>-->
<!--
<user-overridesuser="swaldman">
<propertyname="debugUnreturnedConnectionStackTraces">true</property>
</user-overrides>
-->
</default-config>
<!--
<named-configname="dumbTestConfig">
<propertyname="maxStatements">200</property>
<propertyname="jdbcUrl">jdbc:test</property>
<user-overridesuser="poop">
<propertyname="maxStatements">300</property>
</user-overrides>
</named-config>
-->
</c3p0-config>
<default-config>
<!--<propertyname="automaticTestTable">con_test</property>-->
<!--<propertyname="checkoutTimeout">30000</property>-->
<!--<propertyname="idleConnectionTestPeriod">30</property>-->
<!--<propertyname="initialPoolSize">10</property>-->
<!--<propertyname="maxIdleTime">30</property>-->
<!--<propertyname="maxIdleTimeExcessConnections">10</property>-->
<!--<propertyname="maxConnectionAge">60</property>-->
<!--<propertyname="propertyCycle">1</property>-->
<!--<propertyname="maxPoolSize">25</property>-->
<!--<propertyname="minPoolSize">5</property>-->
<!--<propertyname="maxStatements">0</property>-->
<!--<propertyname="maxStatementsPerConnection">5</property>-->
<!--<propertyname="maxAdministrativeTaskTime">4</property>-->
<!--<propertyname="connectionCustomizerClassName">com.mchange.v2.c3p0.test.TestConnectionCustomizer</property>-->
<!--<propertyname="unreturnedConnectionTimeout">15</property>-->
<!--<propertyname="debugUnreturnedConnectionStackTraces">true</property>-->
<!--
<user-overridesuser="swaldman">
<propertyname="debugUnreturnedConnectionStackTraces">true</property>
</user-overrides>
-->
</default-config>
<!--
<named-configname="dumbTestConfig">
<propertyname="maxStatements">200</property>
<propertyname="jdbcUrl">jdbc:test</property>
<user-overridesuser="poop">
<propertyname="maxStatements">300</property>
</user-overrides>
</named-config>
-->
</c3p0-config>
//解析properties
/*
*Distributedaspartofc3p0v.0.9.1.2
*
*Copyright(C)2005MachineryForChange,Inc.
*
*Author:SteveWaldman<swaldman@mchange.com>
*
*Thislibraryisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as
*publishedbytheFreeSoftwareFoundation.
*
*Thissoftwareisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULesserGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense
*alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe
*FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330,
*Boston,MA02111-1307,USA.
*/
packagecom.mchange.v2.c3p0.cfg;
importjava.io.*;
importjava.lang.reflect.*;
importjava.util.*;
importcom.mchange.v2.cfg.*;
importcom.mchange.v2.log.*;
importcom.mchange.v2.c3p0.impl.*;
publicfinalclassC3P0ConfigUtils
{
publicfinalstaticStringPROPS_FILE_RSRC_PATH="/c3p0.properties";
publicfinalstaticStringPROPS_FILE_PROP_PFX="c3p0.";
publicfinalstaticintPROPS_FILE_PROP_PFX_LEN=5;
privatefinalstaticString[]MISSPELL_PFXS={"/c3pO","/c3po","/C3P0","/C3PO"};
finalstaticMLoggerlogger=MLog.getLogger(C3P0ConfigUtils.class);
static
{
if(logger.isLoggable(MLevel.WARNING)&&C3P0ConfigUtils.class.getResource(PROPS_FILE_RSRC_PATH)==null)
{
//warnonamisspelling...itsanuglywaytodothis,butsinceresourcesarenotlistable...
for(inti=0;i<MISSPELL_PFXS.length;++i)
{
Stringtest=MISSPELL_PFXS[i]+".properties";
if(C3P0ConfigUtils.class.getResource(MISSPELL_PFXS[i]+".properties")!=null)
{
logger.warning("POSSIBLYMISSPELLEDc3p0.propertiesCONFIGRESOURCEFOUND."+
"Pleaseensurethefilenameisc3p0.properties,alllowercase,"+
"withthedigit0(NOTtheletterO)inc3p0.Itshouldbeplaced"+
"inthetoplevelofc3p0'seffectiveclasspath.");
break;
}
}
}
}
publicstaticHashMapextractHardcodedC3P0Defaults(booleanstringify)
{
HashMapout=newHashMap();
try
{
Method[]methods=C3P0Defaults.class.getMethods();
for(inti=0,len=methods.length;i<len;++i)
{
Methodm=methods[i];
intmods=m.getModifiers();
if((mods&Modifier.PUBLIC)!=0&&(mods&Modifier.STATIC)!=0&&m.getParameterTypes().length==0)
{
if(stringify)
{
Objectval=m.invoke(null,null);
if(val!=null)
out.put(m.getName(),String.valueOf(val));
}
else
out.put(m.getName(),m.invoke(null,null));
}
}
}
catch(Exceptione)
{
logger.log(MLevel.WARNING,"Failedtoextracthardcodeddefaultconfig!?",e);
}
returnout;
}
publicstaticHashMapextractHardcodedC3P0Defaults()
{returnextractHardcodedC3P0Defaults(true);}
publicstaticHashMapextractC3P0PropertiesResources()
{
HashMapout=newHashMap();
//Propertiesprops=findResourceProperties();
//props.putAll(findAllC3P0Properties());
Propertiesprops=findAllC3P0Properties();
for(Iteratorii=props.keySet().iterator();ii.hasNext();)
{
Stringkey=(String)ii.next();
Stringval=(String)props.get(key);
if(key.startsWith(PROPS_FILE_PROP_PFX))
out.put(key.substring(PROPS_FILE_PROP_PFX_LEN).trim(),val.trim());
}
returnout;
}
publicstaticC3P0ConfigconfigFromFlatDefaults(HashMapflatDefaults)
{
NamedScopedefaults=newNamedScope();
defaults.props.putAll(flatDefaults);
HashMapconfigNamesToNamedScopes=newHashMap();
returnnewC3P0Config(defaults,configNamesToNamedScopes);
}
publicstaticStringgetPropFileConfigProperty(Stringprop)
{returnMultiPropertiesConfig.readVmConfig().getProperty(prop);}
privatestaticPropertiesfindResourceProperties()
{returnMultiPropertiesConfig.readVmConfig().getPropertiesByResourcePath(PROPS_FILE_RSRC_PATH);}
privatestaticPropertiesfindAllC3P0Properties()
{returnMultiPropertiesConfig.readVmConfig().getPropertiesByPrefix("c3p0");}
staticPropertiesfindAllC3P0SystemProperties()
{
Propertiesout=newProperties();
SecurityExceptionsampleExc=null;
try
{
for(Iteratorii=C3P0Defaults.getKnownProperties().iterator();ii.hasNext();)
{
Stringkey=(String)ii.next();
StringprefixedKey="c3p0."+key;
Stringvalue=System.getProperty(prefixedKey);
if(value!=null&&value.trim().length()>0)
out.put(key,value);
}
}
catch(SecurityExceptione)
{sampleExc=e;}
returnout;
}
privateC3P0ConfigUtils()
{}
}
*Distributedaspartofc3p0v.0.9.1.2
*
*Copyright(C)2005MachineryForChange,Inc.
*
*Author:SteveWaldman<swaldman@mchange.com>
*
*Thislibraryisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as
*publishedbytheFreeSoftwareFoundation.
*
*Thissoftwareisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULesserGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense
*alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe
*FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330,
*Boston,MA02111-1307,USA.
*/
packagecom.mchange.v2.c3p0.cfg;
importjava.io.*;
importjava.lang.reflect.*;
importjava.util.*;
importcom.mchange.v2.cfg.*;
importcom.mchange.v2.log.*;
importcom.mchange.v2.c3p0.impl.*;
publicfinalclassC3P0ConfigUtils
{
publicfinalstaticStringPROPS_FILE_RSRC_PATH="/c3p0.properties";
publicfinalstaticStringPROPS_FILE_PROP_PFX="c3p0.";
publicfinalstaticintPROPS_FILE_PROP_PFX_LEN=5;
privatefinalstaticString[]MISSPELL_PFXS={"/c3pO","/c3po","/C3P0","/C3PO"};
finalstaticMLoggerlogger=MLog.getLogger(C3P0ConfigUtils.class);
static
{
if(logger.isLoggable(MLevel.WARNING)&&C3P0ConfigUtils.class.getResource(PROPS_FILE_RSRC_PATH)==null)
{
//warnonamisspelling...itsanuglywaytodothis,butsinceresourcesarenotlistable...
for(inti=0;i<MISSPELL_PFXS.length;++i)
{
Stringtest=MISSPELL_PFXS[i]+".properties";
if(C3P0ConfigUtils.class.getResource(MISSPELL_PFXS[i]+".properties")!=null)
{
logger.warning("POSSIBLYMISSPELLEDc3p0.propertiesCONFIGRESOURCEFOUND."+
"Pleaseensurethefilenameisc3p0.properties,alllowercase,"+
"withthedigit0(NOTtheletterO)inc3p0.Itshouldbeplaced"+
"inthetoplevelofc3p0'seffectiveclasspath.");
break;
}
}
}
}
publicstaticHashMapextractHardcodedC3P0Defaults(booleanstringify)
{
HashMapout=newHashMap();
try
{
Method[]methods=C3P0Defaults.class.getMethods();
for(inti=0,len=methods.length;i<len;++i)
{
Methodm=methods[i];
intmods=m.getModifiers();
if((mods&Modifier.PUBLIC)!=0&&(mods&Modifier.STATIC)!=0&&m.getParameterTypes().length==0)
{
if(stringify)
{
Objectval=m.invoke(null,null);
if(val!=null)
out.put(m.getName(),String.valueOf(val));
}
else
out.put(m.getName(),m.invoke(null,null));
}
}
}
catch(Exceptione)
{
logger.log(MLevel.WARNING,"Failedtoextracthardcodeddefaultconfig!?",e);
}
returnout;
}
publicstaticHashMapextractHardcodedC3P0Defaults()
{returnextractHardcodedC3P0Defaults(true);}
publicstaticHashMapextractC3P0PropertiesResources()
{
HashMapout=newHashMap();
//Propertiesprops=findResourceProperties();
//props.putAll(findAllC3P0Properties());
Propertiesprops=findAllC3P0Properties();
for(Iteratorii=props.keySet().iterator();ii.hasNext();)
{
Stringkey=(String)ii.next();
Stringval=(String)props.get(key);
if(key.startsWith(PROPS_FILE_PROP_PFX))
out.put(key.substring(PROPS_FILE_PROP_PFX_LEN).trim(),val.trim());
}
returnout;
}
publicstaticC3P0ConfigconfigFromFlatDefaults(HashMapflatDefaults)
{
NamedScopedefaults=newNamedScope();
defaults.props.putAll(flatDefaults);
HashMapconfigNamesToNamedScopes=newHashMap();
returnnewC3P0Config(defaults,configNamesToNamedScopes);
}
publicstaticStringgetPropFileConfigProperty(Stringprop)
{returnMultiPropertiesConfig.readVmConfig().getProperty(prop);}
privatestaticPropertiesfindResourceProperties()
{returnMultiPropertiesConfig.readVmConfig().getPropertiesByResourcePath(PROPS_FILE_RSRC_PATH);}
privatestaticPropertiesfindAllC3P0Properties()
{returnMultiPropertiesConfig.readVmConfig().getPropertiesByPrefix("c3p0");}
staticPropertiesfindAllC3P0SystemProperties()
{
Propertiesout=newProperties();
SecurityExceptionsampleExc=null;
try
{
for(Iteratorii=C3P0Defaults.getKnownProperties().iterator();ii.hasNext();)
{
Stringkey=(String)ii.next();
StringprefixedKey="c3p0."+key;
Stringvalue=System.getProperty(prefixedKey);
if(value!=null&&value.trim().length()>0)
out.put(key,value);
}
}
catch(SecurityExceptione)
{sampleExc=e;}
returnout;
}
privateC3P0ConfigUtils()
{}
}
//解析xml
/*
*Distributedaspartofc3p0v.0.9.1.2
*
*Copyright(C)2005MachineryForChange,Inc.
*
*Author:SteveWaldman<swaldman@mchange.com>
*
*Thislibraryisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as
*publishedbytheFreeSoftwareFoundation.
*
*Thissoftwareisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULesserGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense
*alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe
*FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330,
*Boston,MA02111-1307,USA.
*/
packagecom.mchange.v2.c3p0.cfg;
importjava.io.*;
importjava.util.*;
importjavax.xml.parsers.*;
importorg.w3c.dom.*;
importcom.mchange.v2.log.*;
importcom.mchange.v1.xml.DomParseUtils;
publicfinalclassC3P0ConfigXmlUtils
{
publicfinalstaticStringXML_CONFIG_RSRC_PATH="/c3p0-config.xml";
finalstaticMLoggerlogger=MLog.getLogger(C3P0ConfigXmlUtils.class);
publicfinalstaticStringLINESEP;
privatefinalstaticString[]MISSPELL_PFXS={"/c3p0","/c3pO","/c3po","/C3P0","/C3PO"};
privatefinalstaticchar[]MISSPELL_LINES={'-','_'};
privatefinalstaticString[]MISSPELL_CONFIG={"config","CONFIG"};
privatefinalstaticString[]MISSPELL_XML={"xml","XML"};
//itsanuglywaytodothis,butsinceresourcesarenotlistable...
//
//thisisonlyexecutedonce,anddoesabout40tests(fornow)
//shouldIcareaboutthecostininitializationtime?
//
//shouldonlyberunifwe'vecheckedforthecorrectfile,but
//notfoundit
privatefinalstaticvoidwarnCommonXmlConfigResourceMisspellings()
{
if(logger.isLoggable(MLevel.WARNING))
{
for(inta=0,lena=MISSPELL_PFXS.length;a<lena;++a)
{
StringBuffersb=newStringBuffer(16);
sb.append(MISSPELL_PFXS[a]);
for(intb=0,lenb=MISSPELL_LINES.length;b<lenb;++b)
{
sb.append(MISSPELL_LINES[b]);
for(intc=0,lenc=MISSPELL_CONFIG.length;c<lenc;++c)
{
sb.append(MISSPELL_CONFIG[c]);
sb.append('.');
for(intd=0,lend=MISSPELL_XML.length;d<lend;++d)
{
sb.append(MISSPELL_XML[d]);
Stringtest=sb.toString();
if(!test.equals(XML_CONFIG_RSRC_PATH))
{
ObjecthopefullyNull=C3P0ConfigXmlUtils.class.getResource(test);
if(hopefullyNull!=null)
{
logger.warning("POSSIBLYMISSPELLEDc3p0-conf.xmlRESOURCEFOUND."+
"Pleaseensurethefilenameisc3p0-config.xml,alllowercase,"+
"withthedigit0(NOTtheletterO)inc3p0.Itshouldbeplaced"+
"inthetoplevelofc3p0'seffectiveclasspath.");
return;
}
}
}
}
}
}
}
}
static
{
Stringls;
try
{ls=System.getProperty("line.separator","");}
catch(Exceptione)
{ls="";}
LINESEP=ls;
}
publicstaticC3P0ConfigextractXmlConfigFromDefaultResource()throwsException
{
InputStreamis=null;
try
{
is=C3P0ConfigUtils.class.getResourceAsStream(XML_CONFIG_RSRC_PATH);
if(is==null)
{
warnCommonXmlConfigResourceMisspellings();
returnnull;
}
else
returnextractXmlConfigFromInputStream(is);
}
finally
{
try{if(is!=null)is.close();}
catch(Exceptione)
{
if(logger.isLoggable(MLevel.FINE))
logger.log(MLevel.FINE,"ExceptiononresourceInputStreamclose.",e);
}
}
}
publicstaticC3P0ConfigextractXmlConfigFromInputStream(InputStreamis)throwsException
{
DocumentBuilderFactoryfact=DocumentBuilderFactory.newInstance();
DocumentBuilderdb=fact.newDocumentBuilder();
Documentdoc=db.parse(is);
returnextractConfigFromXmlDoc(doc);
}
publicstaticC3P0ConfigextractConfigFromXmlDoc(Documentdoc)throwsException
{
ElementdocElem=doc.getDocumentElement();
if(docElem.getTagName().equals("c3p0-config"))
{
NamedScopedefaults;
HashMapconfigNamesToNamedScopes=newHashMap();
ElementdefaultConfigElem=DomParseUtils.uniqueChild(docElem,"default-config");
if(defaultConfigElem!=null)
defaults=extractNamedScopeFromLevel(defaultConfigElem);
else
defaults=newNamedScope();
NodeListnl=DomParseUtils.immediateChildElementsByTagName(docElem,"named-config");
for(inti=0,len=nl.getLength();i<len;++i)
{
ElementnamedConfigElem=(Element)nl.item(i);
StringconfigName=namedConfigElem.getAttribute("name");
if(configName!=null&&configName.length()>0)
{
NamedScopenamedConfig=extractNamedScopeFromLevel(namedConfigElem);
configNamesToNamedScopes.put(configName,namedConfig);
}
else
logger.warning("ConfigurationXMLcontainednamed-configelementwithoutnameattribute:"+namedConfigElem);
}
returnnewC3P0Config(defaults,configNamesToNamedScopes);
}
else
thrownewException("Rootelementofc3p0configxmlshouldbe'c3p0-config',not'"+docElem.getTagName()+"'.");
}
privatestaticNamedScopeextractNamedScopeFromLevel(Elementelem)
{
HashMapprops=extractPropertiesFromLevel(elem);
HashMapuserNamesToOverrides=newHashMap();
NodeListnl=DomParseUtils.immediateChildElementsByTagName(elem,"user-overrides");
for(inti=0,len=nl.getLength();i<len;++i)
{
ElementperUserConfigElem=(Element)nl.item(i);
StringuserName=perUserConfigElem.getAttribute("user");
if(userName!=null&&userName.length()>0)
{
HashMapuserProps=extractPropertiesFromLevel(perUserConfigElem);
userNamesToOverrides.put(userName,userProps);
}
else
logger.warning("ConfigurationXMLcontaineduser-overrideselementwithoutuserattribute:"+LINESEP+perUserConfigElem);
}
returnnewNamedScope(props,userNamesToOverrides);
}
privatestaticHashMapextractPropertiesFromLevel(Elementelem)
{
//System.err.println("extractPropertiesFromLevel()");
HashMapout=newHashMap();
try
{
NodeListnl=DomParseUtils.immediateChildElementsByTagName(elem,"property");
intlen=nl.getLength();
for(inti=0;i<len;++i)
{
ElementpropertyElem=(Element)nl.item(i);
StringpropName=propertyElem.getAttribute("name");
if(propName!=null&&propName.length()>0)
{
StringpropVal=DomParseUtils.allTextFromElement(propertyElem,true);
out.put(propName,propVal);
//System.err.println(propName+"->"+propVal);
}
else
logger.warning("ConfigurationXMLcontainedpropertyelementwithoutnameattribute:"+LINESEP+propertyElem);
}
}
catch(Exceptione)
{
logger.log(MLevel.WARNING,
"AnexceptionoccurredwhilereadingconfigXML."+
"Someconfigurationinformationhasprobablybeenignored.",
e);
}
returnout;
}
privateC3P0ConfigXmlUtils()
{}
}
*Distributedaspartofc3p0v.0.9.1.2
*
*Copyright(C)2005MachineryForChange,Inc.
*
*Author:SteveWaldman<swaldman@mchange.com>
*
*Thislibraryisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as
*publishedbytheFreeSoftwareFoundation.
*
*Thissoftwareisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULesserGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense
*alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe
*FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330,
*Boston,MA02111-1307,USA.
*/
packagecom.mchange.v2.c3p0.cfg;
importjava.io.*;
importjava.util.*;
importjavax.xml.parsers.*;
importorg.w3c.dom.*;
importcom.mchange.v2.log.*;
importcom.mchange.v1.xml.DomParseUtils;
publicfinalclassC3P0ConfigXmlUtils
{
publicfinalstaticStringXML_CONFIG_RSRC_PATH="/c3p0-config.xml";
finalstaticMLoggerlogger=MLog.getLogger(C3P0ConfigXmlUtils.class);
publicfinalstaticStringLINESEP;
privatefinalstaticString[]MISSPELL_PFXS={"/c3p0","/c3pO","/c3po","/C3P0","/C3PO"};
privatefinalstaticchar[]MISSPELL_LINES={'-','_'};
privatefinalstaticString[]MISSPELL_CONFIG={"config","CONFIG"};
privatefinalstaticString[]MISSPELL_XML={"xml","XML"};
//itsanuglywaytodothis,butsinceresourcesarenotlistable...
//
//thisisonlyexecutedonce,anddoesabout40tests(fornow)
//shouldIcareaboutthecostininitializationtime?
//
//shouldonlyberunifwe'vecheckedforthecorrectfile,but
//notfoundit
privatefinalstaticvoidwarnCommonXmlConfigResourceMisspellings()
{
if(logger.isLoggable(MLevel.WARNING))
{
for(inta=0,lena=MISSPELL_PFXS.length;a<lena;++a)
{
StringBuffersb=newStringBuffer(16);
sb.append(MISSPELL_PFXS[a]);
for(intb=0,lenb=MISSPELL_LINES.length;b<lenb;++b)
{
sb.append(MISSPELL_LINES[b]);
for(intc=0,lenc=MISSPELL_CONFIG.length;c<lenc;++c)
{
sb.append(MISSPELL_CONFIG[c]);
sb.append('.');
for(intd=0,lend=MISSPELL_XML.length;d<lend;++d)
{
sb.append(MISSPELL_XML[d]);
Stringtest=sb.toString();
if(!test.equals(XML_CONFIG_RSRC_PATH))
{
ObjecthopefullyNull=C3P0ConfigXmlUtils.class.getResource(test);
if(hopefullyNull!=null)
{
logger.warning("POSSIBLYMISSPELLEDc3p0-conf.xmlRESOURCEFOUND."+
"Pleaseensurethefilenameisc3p0-config.xml,alllowercase,"+
"withthedigit0(NOTtheletterO)inc3p0.Itshouldbeplaced"+
"inthetoplevelofc3p0'seffectiveclasspath.");
return;
}
}
}
}
}
}
}
}
static
{
Stringls;
try
{ls=System.getProperty("line.separator","");}
catch(Exceptione)
{ls="";}
LINESEP=ls;
}
publicstaticC3P0ConfigextractXmlConfigFromDefaultResource()throwsException
{
InputStreamis=null;
try
{
is=C3P0ConfigUtils.class.getResourceAsStream(XML_CONFIG_RSRC_PATH);
if(is==null)
{
warnCommonXmlConfigResourceMisspellings();
returnnull;
}
else
returnextractXmlConfigFromInputStream(is);
}
finally
{
try{if(is!=null)is.close();}
catch(Exceptione)
{
if(logger.isLoggable(MLevel.FINE))
logger.log(MLevel.FINE,"ExceptiononresourceInputStreamclose.",e);
}
}
}
publicstaticC3P0ConfigextractXmlConfigFromInputStream(InputStreamis)throwsException
{
DocumentBuilderFactoryfact=DocumentBuilderFactory.newInstance();
DocumentBuilderdb=fact.newDocumentBuilder();
Documentdoc=db.parse(is);
returnextractConfigFromXmlDoc(doc);
}
publicstaticC3P0ConfigextractConfigFromXmlDoc(Documentdoc)throwsException
{
ElementdocElem=doc.getDocumentElement();
if(docElem.getTagName().equals("c3p0-config"))
{
NamedScopedefaults;
HashMapconfigNamesToNamedScopes=newHashMap();
ElementdefaultConfigElem=DomParseUtils.uniqueChild(docElem,"default-config");
if(defaultConfigElem!=null)
defaults=extractNamedScopeFromLevel(defaultConfigElem);
else
defaults=newNamedScope();
NodeListnl=DomParseUtils.immediateChildElementsByTagName(docElem,"named-config");
for(inti=0,len=nl.getLength();i<len;++i)
{
ElementnamedConfigElem=(Element)nl.item(i);
StringconfigName=namedConfigElem.getAttribute("name");
if(configName!=null&&configName.length()>0)
{
NamedScopenamedConfig=extractNamedScopeFromLevel(namedConfigElem);
configNamesToNamedScopes.put(configName,namedConfig);
}
else
logger.warning("ConfigurationXMLcontainednamed-configelementwithoutnameattribute:"+namedConfigElem);
}
returnnewC3P0Config(defaults,configNamesToNamedScopes);
}
else
thrownewException("Rootelementofc3p0configxmlshouldbe'c3p0-config',not'"+docElem.getTagName()+"'.");
}
privatestaticNamedScopeextractNamedScopeFromLevel(Elementelem)
{
HashMapprops=extractPropertiesFromLevel(elem);
HashMapuserNamesToOverrides=newHashMap();
NodeListnl=DomParseUtils.immediateChildElementsByTagName(elem,"user-overrides");
for(inti=0,len=nl.getLength();i<len;++i)
{
ElementperUserConfigElem=(Element)nl.item(i);
StringuserName=perUserConfigElem.getAttribute("user");
if(userName!=null&&userName.length()>0)
{
HashMapuserProps=extractPropertiesFromLevel(perUserConfigElem);
userNamesToOverrides.put(userName,userProps);
}
else
logger.warning("ConfigurationXMLcontaineduser-overrideselementwithoutuserattribute:"+LINESEP+perUserConfigElem);
}
returnnewNamedScope(props,userNamesToOverrides);
}
privatestaticHashMapextractPropertiesFromLevel(Elementelem)
{
//System.err.println("extractPropertiesFromLevel()");
HashMapout=newHashMap();
try
{
NodeListnl=DomParseUtils.immediateChildElementsByTagName(elem,"property");
intlen=nl.getLength();
for(inti=0;i<len;++i)
{
ElementpropertyElem=(Element)nl.item(i);
StringpropName=propertyElem.getAttribute("name");
if(propName!=null&&propName.length()>0)
{
StringpropVal=DomParseUtils.allTextFromElement(propertyElem,true);
out.put(propName,propVal);
//System.err.println(propName+"->"+propVal);
}
else
logger.warning("ConfigurationXMLcontainedpropertyelementwithoutnameattribute:"+LINESEP+propertyElem);
}
}
catch(Exceptione)
{
logger.log(MLevel.WARNING,
"AnexceptionoccurredwhilereadingconfigXML."+
"Someconfigurationinformationhasprobablybeenignored.",
e);
}
returnout;
}
privateC3P0ConfigXmlUtils()
{}
}
/*
*Distributedaspartofc3p0v.0.9.1.2
*
*Copyright(C)2005MachineryForChange,Inc.
*
*Author:SteveWaldman<swaldman@mchange.com>
*
*Thislibraryisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as
*publishedbytheFreeSoftwareFoundation.
*
*Thissoftwareisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULesserGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense
*alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe
*FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330,
*Boston,MA02111-1307,USA.
*/
packagecom.mchange.v1.xml;
importjava.util.*;
importorg.xml.sax.*;
importorg.w3c.dom.*;
importcom.mchange.v1.util.DebugUtils;
publicfinalclassDomParseUtils
{
finalstaticbooleanDEBUG=true;
/**
*@returnnullifchilddoesn'texist.
*/
publicstaticStringallTextFromUniqueChild(Elementelem,StringchildTagName)
throwsDOMException
{returnallTextFromUniqueChild(elem,childTagName,false);}
/**
*@returnnullifchilddoesn'texist.
*/
publicstaticStringallTextFromUniqueChild(Elementelem,StringchildTagName,booleantrim)
throwsDOMException
{
ElementuniqueChild=uniqueChildByTagName(elem,childTagName);
if(uniqueChild==null)
returnnull;
else
returnDomParseUtils.allTextFromElement(uniqueChild,trim);
}
publicstaticElementuniqueChild(Elementelem,StringchildTagName)throwsDOMException
{returnuniqueChildByTagName(elem,childTagName);}
/**
*@deprecateduseuniqueChild(Elementelem,StringchildTagName)
*/
publicstaticElementuniqueChildByTagName(Elementelem,StringchildTagName)throwsDOMException
{
NodeListnl=elem.getElementsByTagName(childTagName);
intlen=nl.getLength();
if(DEBUG)
DebugUtils.myAssert(len<=1,
"Thereismorethanone("+len+")childwithtagname:"+
childTagName+"!!!");
return(len==1?(Element)nl.item(0):null);
}
publicstaticStringallText(Elementelem)throwsDOMException
{returnallTextFromElement(elem);}
publicstaticStringallText(Elementelem,booleantrim)throwsDOMException
{returnallTextFromElement(elem,trim);}
/**@deprecateduseallText(Elementelem)*/
publicstaticStringallTextFromElement(Elementelem)throwsDOMException
{returnallTextFromElement(elem,false);}
/**@deprecateduseallText(Elementelem,booleantrim)*/
publicstaticStringallTextFromElement(Elementelem,booleantrim)throwsDOMException
{
StringBuffertextBuf=newStringBuffer();
NodeListnl=elem.getChildNodes();
for(intj=0,len=nl.getLength();j<len;++j)
{
Nodenode=nl.item(j);
if(nodeinstanceofText)//includesTextandCDATA!
textBuf.append(node.getNodeValue());
}
Stringout=textBuf.toString();
return(trim?out.trim():out);
}
publicstaticString[]allTextFromImmediateChildElements(Elementparent,StringtagName)
throwsDOMException
{returnallTextFromImmediateChildElements(parent,tagName,false);}
publicstaticString[]allTextFromImmediateChildElements(Elementparent,StringtagName,booleantrim)
throwsDOMException
{
NodeListnl=immediateChildElementsByTagName(parent,tagName);
intlen=nl.getLength();
String[]out=newString[len];
for(inti=0;i<len;++i)
out[i]=allText((Element)nl.item(i),trim);
returnout;
}
publicstaticNodeListimmediateChildElementsByTagName(Elementparent,StringtagName)
throwsDOMException
{returngetImmediateChildElementsByTagName(parent,tagName);}
/**
*@deprecateduseimmediateChildrenByTagName(Elementparent,StringtagName)
*/
publicstaticNodeListgetImmediateChildElementsByTagName(Elementparent,StringtagName)
throwsDOMException
{
finalListnodes=newArrayList();
for(Nodechild=parent.getFirstChild();child!=null;child=child.getNextSibling())
if(childinstanceofElement&&((Element)child).getTagName().equals(tagName))
nodes.add(child);
returnnewNodeList()
{
publicintgetLength()
{returnnodes.size();}
publicNodeitem(inti)
{return(Node)nodes.get(i);}
};
}
publicstaticStringallTextFromUniqueImmediateChild(Elementelem,StringchildTagName)
throwsDOMException
{
ElementuniqueChild=uniqueImmediateChildByTagName(elem,childTagName);
if(uniqueChild==null)
returnnull;
returnDomParseUtils.allTextFromElement(uniqueChild);
}
publicstaticElementuniqueImmediateChild(Elementelem,StringchildTagName)
throwsDOMException
{returnuniqueImmediateChildByTagName(elem,childTagName);}
/**
*@deprecateduseuniqueImmediateChild(Elementelem,StringchildTagName)
*/
publicstaticElementuniqueImmediateChildByTagName(Elementelem,StringchildTagName)
throwsDOMException
{
NodeListnl=getImmediateChildElementsByTagName(elem,childTagName);
intlen=nl.getLength();
if(DEBUG)
DebugUtils.myAssert(len<=1,
"Thereismorethanone("+len+")childwithtagname:"+
childTagName+"!!!");
return(len==1?(Element)nl.item(0):null);
}
/**
*@deprecateduseElement.getAttribute(Stringval)
*/
publicstaticStringattrValFromElement(Elementelement,StringattrName)
throwsDOMException
{
Attrattr=element.getAttributeNode(attrName);
return(attr==null?null:attr.getValue());
}
privateDomParseUtils()
{}
}
*Distributedaspartofc3p0v.0.9.1.2
*
*Copyright(C)2005MachineryForChange,Inc.
*
*Author:SteveWaldman<swaldman@mchange.com>
*
*Thislibraryisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNULesserGeneralPublicLicenseversion2.1,as
*publishedbytheFreeSoftwareFoundation.
*
*Thissoftwareisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNULesserGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense
*alongwiththissoftware;seethefileLICENSE.Ifnot,writetothe
*FreeSoftwareFoundation,Inc.,59TemplePlace,Suite330,
*Boston,MA02111-1307,USA.
*/
packagecom.mchange.v1.xml;
importjava.util.*;
importorg.xml.sax.*;
importorg.w3c.dom.*;
importcom.mchange.v1.util.DebugUtils;
publicfinalclassDomParseUtils
{
finalstaticbooleanDEBUG=true;
/**
*@returnnullifchilddoesn'texist.
*/
publicstaticStringallTextFromUniqueChild(Elementelem,StringchildTagName)
throwsDOMException
{returnallTextFromUniqueChild(elem,childTagName,false);}
/**
*@returnnullifchilddoesn'texist.
*/
publicstaticStringallTextFromUniqueChild(Elementelem,StringchildTagName,booleantrim)
throwsDOMException
{
ElementuniqueChild=uniqueChildByTagName(elem,childTagName);
if(uniqueChild==null)
returnnull;
else
returnDomParseUtils.allTextFromElement(uniqueChild,trim);
}
publicstaticElementuniqueChild(Elementelem,StringchildTagName)throwsDOMException
{returnuniqueChildByTagName(elem,childTagName);}
/**
*@deprecateduseuniqueChild(Elementelem,StringchildTagName)
*/
publicstaticElementuniqueChildByTagName(Elementelem,StringchildTagName)throwsDOMException
{
NodeListnl=elem.getElementsByTagName(childTagName);
intlen=nl.getLength();
if(DEBUG)
DebugUtils.myAssert(len<=1,
"Thereismorethanone("+len+")childwithtagname:"+
childTagName+"!!!");
return(len==1?(Element)nl.item(0):null);
}
publicstaticStringallText(Elementelem)throwsDOMException
{returnallTextFromElement(elem);}
publicstaticStringallText(Elementelem,booleantrim)throwsDOMException
{returnallTextFromElement(elem,trim);}
/**@deprecateduseallText(Elementelem)*/
publicstaticStringallTextFromElement(Elementelem)throwsDOMException
{returnallTextFromElement(elem,false);}
/**@deprecateduseallText(Elementelem,booleantrim)*/
publicstaticStringallTextFromElement(Elementelem,booleantrim)throwsDOMException
{
StringBuffertextBuf=newStringBuffer();
NodeListnl=elem.getChildNodes();
for(intj=0,len=nl.getLength();j<len;++j)
{
Nodenode=nl.item(j);
if(nodeinstanceofText)//includesTextandCDATA!
textBuf.append(node.getNodeValue());
}
Stringout=textBuf.toString();
return(trim?out.trim():out);
}
publicstaticString[]allTextFromImmediateChildElements(Elementparent,StringtagName)
throwsDOMException
{returnallTextFromImmediateChildElements(parent,tagName,false);}
publicstaticString[]allTextFromImmediateChildElements(Elementparent,StringtagName,booleantrim)
throwsDOMException
{
NodeListnl=immediateChildElementsByTagName(parent,tagName);
intlen=nl.getLength();
String[]out=newString[len];
for(inti=0;i<len;++i)
out[i]=allText((Element)nl.item(i),trim);
returnout;
}
publicstaticNodeListimmediateChildElementsByTagName(Elementparent,StringtagName)
throwsDOMException
{returngetImmediateChildElementsByTagName(parent,tagName);}
/**
*@deprecateduseimmediateChildrenByTagName(Elementparent,StringtagName)
*/
publicstaticNodeListgetImmediateChildElementsByTagName(Elementparent,StringtagName)
throwsDOMException
{
finalListnodes=newArrayList();
for(Nodechild=parent.getFirstChild();child!=null;child=child.getNextSibling())
if(childinstanceofElement&&((Element)child).getTagName().equals(tagName))
nodes.add(child);
returnnewNodeList()
{
publicintgetLength()
{returnnodes.size();}
publicNodeitem(inti)
{return(Node)nodes.get(i);}
};
}
publicstaticStringallTextFromUniqueImmediateChild(Elementelem,StringchildTagName)
throwsDOMException
{
ElementuniqueChild=uniqueImmediateChildByTagName(elem,childTagName);
if(uniqueChild==null)
returnnull;
returnDomParseUtils.allTextFromElement(uniqueChild);
}
publicstaticElementuniqueImmediateChild(Elementelem,StringchildTagName)
throwsDOMException
{returnuniqueImmediateChildByTagName(elem,childTagName);}
/**
*@deprecateduseuniqueImmediateChild(Elementelem,StringchildTagName)
*/
publicstaticElementuniqueImmediateChildByTagName(Elementelem,StringchildTagName)
throwsDOMException
{
NodeListnl=getImmediateChildElementsByTagName(elem,childTagName);
intlen=nl.getLength();
if(DEBUG)
DebugUtils.myAssert(len<=1,
"Thereismorethanone("+len+")childwithtagname:"+
childTagName+"!!!");
return(len==1?(Element)nl.item(0):null);
}
/**
*@deprecateduseElement.getAttribute(Stringval)
*/
publicstaticStringattrValFromElement(Elementelement,StringattrName)
throwsDOMException
{
Attrattr=element.getAttributeNode(attrName);
return(attr==null?null:attr.getValue());
}
privateDomParseUtils()
{}
}
相关推荐
<c3p0-config> <!--默认配置--> <default-config> <property name="initialPoolSize">10</property> <property name="maxIdleTime">30</property> <property name="maxPoolSize">100</property> ...
这些可以通过编程方式或者在配置文件(如c3p0-config.xml)中设定。 在Java代码中,通常通过以下方式初始化c3p0连接池: ```java Properties props = new Properties(); props.setProperty("user", "username"); ...
标题 "c3p0+xml+jdbc.properties+DBUtils+mysql-connector" 提示我们讨论的是一个基于Java的数据库连接管理方案,它涉及到几个关键组件:C3P0连接池、XML配置、`jdbc.properties`配置文件以及MySQL的JDBC驱动。...
综上所述,使用C3P0管理数据库连接的关键在于正确配置`init.properties`文件,以及将其与Spring框架集成,从而实现高效、稳定的数据库连接管理。这不仅能够显著提升应用的性能,还能简化数据库操作的复杂性,是Java ...
`c3p0-config.xml`是c3p0的XML配置文件,提供了更灵活的方式来定义连接池的配置,可以替代`c3p0.properties`。 配置示例: - 对于c3p0,你可以在`c3p0-config.xml`中配置如下: ```xml <data-source class=...
- **配置文件**: c3p0的配置通常在`c3p0.properties`文件中进行,例如: ``` com.mchange.v2.c3p0.jdbcUrl=jdbc:mysql://localhost:3306/mydb com.mchange.v2.c3p0.username=myuser ...
如何使用c3p0数据库连接池jar包: 1.导入两个jar包:c3p0-...2.定义配置文件(可直接放在src文件夹下):c3p0.properties或c3p0-config.xml 3.创建数据库连接池对象ComboPooledDatasource 4.获取连接:getConnection
<value>file:./config/c3p0.properties ``` 这里,`PropertyPlaceholderConfigurer` bean用于读取并解析外部属性文件,`locations`属性指定了属性文件的位置。注意路径需要根据实际项目结构进行调整。 然后...
除了资源文件配置外,C3P0也可以通过XML配置文件(如`c3p0-config.xml`)进行设置,这种方式更加灵活,可以针对不同的数据源设定不同的配置。例如: ```xml <data-source> <class-name>...
`c3p0-config.xml`是c3p0的默认配置文件,其中包含了连接池的各种参数设置。以下是一些常见的配置项: - `minPoolSize`:最小连接池大小,即连接池在空闲时至少保持的连接数量。 - `maxPoolSize`:最大连接池大小,...
cpds.setProperties(new Properties("c3p0-config.xml")); Connection conn = cpds.getConnection(); ``` 获取到`Connection`对象后,就可以进行数据库操作了。 5. **C3P0的优势**: - 自动管理连接,减少了...
2. **配置C3P0.properties**:C3P0可以通过配置文件进行设置,如`c3p0-config.xml`或`c3p0.properties`。这个压缩包中可能包含的是`c3p0.properties`,在文件中定义数据库连接的属性,如数据库URL、用户名、密码、...
C3P0:数据库连接池技术 步骤: 1.导入jar包 c3p0-0.9.5.2....名称:c3p0.properties 或者 c3p0-config.xml 路径:直接将文件放在src目录下即可 3.创建数据库连接池对象 ComboPooledDataSource 4.获取连接 getConnection
c3p0的核心配置文件通常命名为`c3p0-config.xml`,在这个文件中,你可以设置各种参数来调整连接池的行为,如初始化连接数、最大连接数、超时时间等。例如: ```xml <data-source> <class-name>...
C3P0的配置主要通过`c3p0-config.xml`文件进行,这个文件通常放在项目的类路径下。配置文件包括了以下主要参数: 1. `minPoolSize`:最小连接池大小,即系统启动时初始化的连接数量。 2. `maxPoolSize`:最大连接池...
- 在Spring框架中,可以通过`c3p0-config.xml`配置文件或`@Bean`注解将C3P0连接池集成到应用中。 - 在非Spring环境中,可以通过JDBC的`DriverManagerDataSource`或`BasicDataSource`结合C3P0的`...
主要讲解c3p0数据源的三种配置方式 c3p0三种配置方式 c3p0的配置方式分为三种,分别是 1.setters一个个地设置各个配置项 2.类路径下提供一个c3p0.properties文件 3.类路径下提供一个c3p0-config.xml文件
<property name="hibernate.c3p0.config_file">classpath:c3p0.properties ``` 4. **应用配置**:在应用启动时,通过Hibernate的SessionFactory初始化c3p0数据连接池。 **重要配置参数说明:** - `minPoolSize`...