样式测试

  1. package  com.netskycn;  
  2. import  java.sql.Connection;  
  3. import  java.sql.ResultSet;  
  4. import  java.sql.SQLException;  
  5. import  java.sql.Statement;  
  6.   
  7. import  com.jolbox.bonecp.BoneCP;  
  8. import  com.jolbox.bonecp.BoneCPConfig;  
  9.    
  10. /** 测试bonecp数据库连接池的工具  
  11.  * @author zhoufoxcn 周公  
  12.  * @version 0.1  
  13.  * 说明:这是一个在JDBC中使用BoneCP的例子  
  14.  * 2010-11-23  
  15.  */   
  16. public   class  MainClass {  
  17.     public   static   void  main(String[] args) {  
  18.         BoneCP connectionPool = null ;  
  19.         Connection connection = null ;  
  20.    
  21.         try  {  
  22.             //加载JDBC驱动   
  23.             Class.forName("com.mysql.jdbc.Driver" );  
  24.         } catch  (Exception e) {  
  25.             e.printStackTrace();  
  26.             return ;  
  27.         }  
  28.           
  29.         try  {  
  30.             //设置连接池配置信息   
  31.             BoneCPConfig config = new  BoneCPConfig();  
  32.             //数据库的JDBC URL   
  33.             config.setJdbcUrl("jdbc:mysql:///jobeet" );   
  34.             //数据库用户名   
  35.             config.setUsername("root" );   
  36.             //数据库用户密码   
  37.             config.setPassword("jeri" );  
  38.             //数据库连接池的最小连接数   
  39.             config.setMinConnectionsPerPartition(5 );  
  40.             //数据库连接池的最大连接数   
  41.             config.setMaxConnectionsPerPartition(10 );  
  42.             //   
  43.             config.setPartitionCount(1 );  
  44.             //设置数据库连接池   
  45.             connectionPool = new  BoneCP(config);  
  46.             //从数据库连接池获取一个数据库连接   
  47.             connection = connectionPool.getConnection(); // fetch a connection   
  48.               
  49.             if  (connection !=  null ){  
  50.                 System.out.println("Connection successful!" );  
  51.                 Statement stmt = connection.createStatement();  
  52.                 ResultSet rs = stmt.executeQuery("SELECT * FROM customer" );   
  53.                 while (rs.next()){  
  54.                     System.out.println(rs.getInt(1 )+ ":" +rs.getString( "firstname" )+ "," +rs.getString( "lastname" ));   
  55.                 }  
  56.             }  
  57.             //关闭数据库连接池   
  58.             connectionPool.shutdown();   
  59.         } catch  (SQLException e) {  
  60.             e.printStackTrace();  
  61.         } finally  {  
  62.             if  (connection !=  null ) {  
  63.                 try  {  
  64.                     connection.close();  
  65.                 } catch  (SQLException e) {  
  66.                     e.printStackTrace();  
  67.                 }  
  68.             }  
  69.         }  
  70.     }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值