Java连接池 BoneCP 0.7.0

今天看到BoneCP 0.7.0 正式版发布了,就来看了一下

首先介绍一下BoneCP 0.7.0

BoneCP 0.7.0 版本包含众多改进和调整,另外授权协议由 LGPL 改为 Apache

详情包括:

Features:
+ 新架构使得连接池性能更佳
+ 授权协议由LGPL改为Apache
+ OSGi 支持
+ Add maxConnectionAge to give a maximum time a connection will be kept alive.
+ Add ability to load default XML config file (with overrides)
+ Added onBeforeStatementExecute and onAfterStatementExecute hooks.
+ Added connection/statement handles to onQueryTimeLimitExeceeded (deprecated old version)
+ Support for LIFO queues for better idleConnectionTimeouts.

Fixes
+ Make connectionTimeout 0 behave like max value
+ Don't set username to blank if it is null and respect datasource bean setting
+ Allow minConnections = 0
+ Fixes for hibernate provider (https://bugs.launchpad.net/bonecp/+bug/655288)
+ Pass StatementHandle reference to hook rather than Statement
+ Use StringBuilder where necessary for better performance.1
+ Failures in closing a connection might cause connection to be lost.
+ Other minor cleanups.

Compatibility notes
+ set default partition count to 1
+ Migrated from Google collections library to Google guava
官网 http://jolbox.com/
下载地址:http://jolbox.com/bonecp/downloads/maven/com/jolbox/

API    http://jolbox.com/bonecp/downloads/site/apidocs/index.html

在API中给了这么demo

 

// load the database driver (make sure this is in your classpath!)
Class.forName("org.hsqldb.jdbcDriver");
// setup the connection pool
BoneCPConfig config = new BoneCPConfig();
// jdbc url specific to your database, eg jdbc:mysql://127.0.0.1/yourdb
config.setJdbcUrl("jdbc:hsqldb:mem:test"); 
config.setUsername("sa"); 
config.setPassword("");
config.setMinConnectionsPerPartition(5);
config.setMaxConnectionsPerPartition(10);
config.setPartitionCount(1);
        
connectionPool = new BoneCP(config); // setup the connection pool
                        
connection = connectionPool.getConnection(); // fetch a connection
if (connection != null){
        System.out.println("Connection successful!");
    Statement stmt = connection.createStatement();
    // do something with the connection.
        ResultSet rs = stmt.executeQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS"); 
        while(rs.next()){
                System.out.println(rs.getString(1)); // should print out "1"'
        }
}
                        
connection.close(); // close the connection
connectionPool.shutdown(); // shutdown connection pool.

 

自己还是需要进行修改。

这里我附上自己写的一个demo里面含有jar包 和一个数据库sqlitejdbc-v056.jar

两个执行类,一个是对SQL Server2000操作的。

你可能感兴趣的:(java,maven,jdbc,HSQLDB,osgi)