设为首页 加入收藏

TOP

记性不如烂笔头21-JAVA数据库连接池DBCP(二)
2015-07-24 11:33:44 来源: 作者: 【 】 浏览:9
Tags:记性 不如 笔头 21-JAVA 数据库 连接 DBCP
92.168.19.1:1521:fanfangming"); p.setProperty("password","ffm"); p.setProperty("username","ffm"); p.setProperty("maxActive","30"); p.setProperty("maxIdle","10"); p.setProperty("maxWait","1000"); p.setProperty("removeAbandoned","false"); p.setProperty("removeAbandonedTimeout", "120"); p.setProperty("testOnBorrow","true"); p.setProperty("logAbandoned","true"); dataSource =(BasicDataSource)BasicDataSourceFactory .createDataSource(p); }catch(Exception e) { e.printStackTrace(); } } public static synchronized ConnectiongetConnection() throwsSQLException{ if (dataSource == null) { init(); } Connectionconn = null; if (dataSource != null) { conn= dataSource.getConnection(); } return conn; } public static void main(String[] args) throws Exception { Connectioncon = null; try { con= DbcpUsage.getConnection(); Stringsql = " select sysdate from dual"; PreparedStatement ps =con.prepareStatement(sql); ResultSet rs = ps.executeQuery(); while (rs.next()) { String value =rs.getString("sysdate"); System.out.println(StringUtils.center(value+",数据库连接成功", 50, "-")); } }catch(Exception e) { e.printStackTrace(); }finally{ if (con != null) { con.close(); } } } }

?

运行如下:

?

----------2014-12-1612:38:32.0,数据库连接成功-----------

5、运行结果

运行如下:

?

----------2014-12-1612:38:32.0,数据库连接成功-----------

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇权限 下一篇范式图形辨析

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·PostgreSQL 索引 - (2025-12-25 22:20:43)
·MySQL Node.js 连接 (2025-12-25 22:20:41)
·SQL 撤销索引、表以 (2025-12-25 22:20:38)
·Linux系统简介 (2025-12-25 21:55:25)
·Linux安装MySQL过程 (2025-12-25 21:55:22)