简体   繁体   English

使用c3p0的数据库连接

[英]database connection using c3p0

Currently in my project the datasource , transactionmanager and other bean required for database connectivity are defined in xml file and there values are configured in property file from which it takes to do the connection. 当前,在我的项目中,数据库连接所需的数据源,transactionmanager和其他bean在xml文件中定义,并且在属性文件中配置了用于进行连接的值。 for ex: 例如:

<bean id="DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close" p:driverClass="${DRIVER_CLASS}" p:jdbcUrl="${DB_URL}"
    p:minPoolSize="${MIN_DB_POOL_SIZE}" p:maxPoolSize="${DB_POOL_SIZE}"
    p:maxStatements="${DB_POOL_SIZE}" p:idleConnectionTestPeriod="${IDLE_CONNECTION_TEST_PERIOD}"
    p:loginTeimeout="${LOGIN_TIMEOUT}" scope="singleton"></bean>

ALL these like values ${DB_POOL_SIZE} are configured in property file. 所有这些类似值$ {DB_POOL_SIZE}都在属性文件中配置。 the class com.mchange.v2.c3p0.ComboPooledDataSource is final class and can't be extended. com.mchange.v2.c3p0.ComboPooledDataSource类是最终类,无法扩展。 so my requirement is :when spring create the bean of Datasource i should be able to set the value of the variable in xml(DB_URL) from my java file through setter method. 所以我的要求是:当春天创建数据源的bean时,我应该能够通过setter方法从我的java文件中设置xml(DB_URL)中的变量值。 how to do that? 怎么做?

I don't quite get what you are trying to do, but if your problem is that you'd like to extend ComboPoolDataSource with some custom functionality, just extend AbstractComboPooledDataSource . 我不太了解您要做什么,但是如果您的问题是您想使用某些自定义功能扩展ComboPoolDataSource ,则只需扩展AbstractComboPooledDataSource Check out the source to ComboPooledDataSource . ComboPooledDataSource的源。 There's not much there (once you get past the annoying copyright header). 那里没有很多(一旦您跳过了烦人的版权标头)。 Use that as a template, and extend AbstractComboPooledDataSource however you'd like. 使用它作为模板,并根据需要扩展AbstractComboPooledDataSource

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM