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()
    }
    }

    }
  • 相关阅读:
    题解报告——垃圾陷阱
    后缀自动机
    计算几何之凸包
    平衡树——treap
    图论--最小费用最大流(MCMF)
    很重要的吐槽!
    图论--网络流初步(最大流,增广路)
    字符串--Trie树(字典树)
    图论--Tarjan求强联通分量
    数据结构--堆
  • 原文地址:https://www.cnblogs.com/heguoxiu/p/10064311.html
Copyright © 2011-2022 走看看