zoukankan      html  css  js  c++  java
  • 数据库连接池ConnectionPool

    package com.bnls.test.pool

    import java.sql.{Connection, ResultSet}
    import com.jolbox.bonecp.{BoneCP, BoneCPConfig}
    import org.slf4j.LoggerFactory

    object ConnectionPool {

    val logger = LoggerFactory.getLogger(this.getClass)

    private val connectionPool = {
    try {
    Class.forName("com.mysql.jdbc.Driver")
    val config = new BoneCPConfig()
    config.setJdbcUrl("jdbc:mysql://10.60.81.185:3311/intfdb")
    config.setUsername("intfopr")
    config.setPassword("Qhcmysql%1234")
    config.setLazyInit(true)

    config.setMinConnectionsPerPartition(3)
    config.setMaxConnectionsPerPartition(5)
    config.setPartitionCount(5)
    config.setCloseConnectionWatch(true)
    config.setLogStatementsEnabled(false)

    Some(new BoneCP(config))
    } catch {
    case exception: Exception =>
    logger.warn("Error in creation of connection pool" + exception.printStackTrace())
    None
    }
    }

    def getConnection: Option[Connection] = {
    connectionPool match {
    case Some(connectionPool) => Some(connectionPool.getConnection)
    case None => None
    }
    }

    def closeConnection(connection: Connection): Unit = {
    if (!connection.isClosed) {
    connection.close()
    }
    }

    }
  • 相关阅读:
    字符串的问题(strstr和strncpy 水题)
    数一数(KMP+思维)
    栗酱的数列(KMP+思维)
    D. Almost All Divisors(思维)
    E. Two Arrays and Sum of Functions(贪心)
    好位置(思维)
    Just A String(kmp)
    Dubbo简介
    lambda表达式快速创建
    分布式RPC系统框架Dubbo
  • 原文地址:https://www.cnblogs.com/heguoxiu/p/10064311.html
Copyright © 2011-2022 走看看