zoukankan      html  css  js  c++  java
  • JDBC连接池BoneCP

    public class ExampleDataSource {
        
        public static void main(String[] args) {
            
            Connection connection = null;
            
            try {
                Class.forName("com.mysql.jdbc.Driver");
            } catch (Exception e) {
                e.printStackTrace();
            }
            
            BoneCPDataSource dataSource=new BoneCPDataSource();
            dataSource.setUsername("root");
            dataSource.setPassword("root");
            dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/stopsix_two_phase");
            dataSource.setMaxConnectionsPerPartition(10);
            dataSource.setMinConnectionsPerPartition(5);
            dataSource.setIdleMaxAge(240);
            dataSource.setAcquireIncrement(5);
            dataSource.setReleaseHelperThreads(3);
            dataSource.setIdleConnectionTestPeriod(60);
            dataSource.setPartitionCount(3);
            dataSource.setAcquireIncrement(5);
            dataSource.setStatementsCacheSize(100);
            try {
                connection=dataSource.getConnection();
                if (connection != null){
                    System.out.println("Connection successful!");
                    Statement stmt = connection.createStatement();
                    ResultSet rs = stmt.executeQuery(" select 1+1 numb "); // do something with the connection.
                    while(rs.next()){
                        System.out.println(rs.getString("numb")); // should print out "1"'
                        System.out.println(rs.getInt("numb")); // should print out 1
                    }
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }finally{
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            
            
        }
        
    }

    jar包:

    bonecp-0.7.1.RELEASE.jar,

    guava-14.0.1.jar,

    log4j-1.2.16.jar,

    mysql-connector-java-5.1.33.jar,

    slf4j-api-1.6.1.jar,

    slf4j-log4j12-1.6.1.jar

  • 相关阅读:
    hyper虚拟机下对centos进行动态扩容
    《C#高级编程第七版》多线程之Events
    借鉴StanZhai核心代码,写了个博客园采集器
    文档转换之PDF转换为HTML
    书香电子书下载地址分析器
    c#常用类库及资源
    iis7.5 配置伪静态
    根据枚举类型获取描述
    从客户端检测到有潜在危险的Request.Form值
    Sql行列转换
  • 原文地址:https://www.cnblogs.com/liclBlog/p/15349571.html
Copyright © 2011-2022 走看看