c3p0 mysql无法连接_采用c3p0连接池为啥连不上mysql数据库呢,在线求各位大佬指导...

十一月 11, 2019 8:24:11 下午 com.mchange.v2.log.MLog

信息: MLog clients using java 1.4+ standard logging.

十一月 11, 2019 8:24:12 下午 com.mchange.v2.c3p0.C3P0Registry

信息: Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]

十一月 11, 2019 8:24:12 下午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource

信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1br9q58a6p371979bc1e5|5ef04b5, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1br9q58a6p371979bc1e5|5ef04b5, idleConnectionTestPeriod -> 0, initialPoolSize -> 10, jdbcUrl -> jdbc:mysql://localhost:3306/web?serverTimezone=UTC, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 30, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 100, maxStatements -> 500, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]

Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C3P0是一个流行的Java数据库连接池管理器,它可以帮助你有效地管理和复用数据库连接,避免频繁创建和关闭连接所带来的性能开销。当你使用C3P0MySQL数据库集成时,你需要进行以下几个步骤: 1. **添加依赖**:在你的项目中,首先需要将C3P0库作为Maven或Gradle的依赖添加到构建文件中。 ```xml <!-- Maven --> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.2</version> <!-- 选择合适的版本 --> </dependency> // Gradle implementation 'com.mchange:c3p0:0.9.5.2' ``` 2. **配置初始化**:在应用启动时,需要初始化C3P0连接池。通常会在Spring Boot应用中使用`DataSource`接口的配置。 ```java @Configuration public class DataSourceConfig { @Value("${jdbc.url}") private String url; @Value("${jdbc.user}") private String username; @Value("${jdbc.password}") private String password; @Bean public DataSource dataSource() { c3p0.ComboPooledDataSource dataSource = new c3p0.ComboPooledDataSource(); dataSource.setJdbcUrl(url); dataSource.setUser(username); dataSource.setPassword(password); dataSource.setMaxPoolSize(10); // 设置最大连接数 dataSource.setMinPoolSize(5); // 设置最小连接数 dataSource.setMaxIdleTime(300); // 设置最长空闲时间 return dataSource; } } ``` 3. **注入使用**:在需要使用数据库的地方,你可以通过`@Autowired`注入`DataSource`来获取连接。 ```java @Service public class MyService { @Autowired private DataSource dataSource; public void performTask() { try (Connection connection = dataSource.getConnection()) { // 这里进行数据库操作 } catch (SQLException e) { e.printStackTrace(); } } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值