User Guide 将帮你在Java应用中使用proxool
Quick Start
1.如果你的应用是直接JDBC方式连接数据库.你只需要改变少量的代码就可以应用proxool.例如:
原来的代码:
1.Connection connection = null;
2.try {
3. Class.forName("org.hsqldb.JDBCDriver");
4. try {
5. connection = DriverManager.getConnection("JDBC:hsqldb:test");
6. } catch (SQLException e) {
7. LOG.error("Problem getting connection", e);
8. }
9.
10. if (connection != null) {
11. LOG.info("Got connection :)");
12. } else {
13. LOG.error("Didn't get connection, which probably means that no Driver accepted the URL");
14. }
15.
16.} catch (ClassNotFoundException e) {
17. LOG.error("Couldn't find driver", e);
18.} finally {
19. try {
20. // Check to see we actually got a connection before we
21. // attempt to close it.
22. if (connection != null) {
23. connection.close();
24. }
25. } catch (SQLException e) {
26. LOG.error("Problem closing connection", e);
27. }
28.}
改变后的代码:
.Connection connection = null;
2.try {
3. Class.forName("org.logicalcobWebs.proxool.ProxoolDriver");
4. try {
5. connection = DriverManager.getConnection("proxool.example:org.hsqldb.jdbcDriver:jdbc:hsqldb:test");
6. } catch (SQLException e) {
7. LOG.error("Problem getting connection", e);
8. }
9.
10. if (connection != null) {
11. LOG.info("Got connection :)");
12. } else {
13. LOG.error("Didn't get connection, which probably means that no Driver accepted the URL");
14. }
15.
16.} catch (ClassNotFoundException e) {
17. LOG.error("Couldn't find driver", e);
18.} finally {
19. try {
20. // Check to see we actually got a connection before we
21. // attempt to close it.
22. if (connection != null) {
23. connection.close();
24. }
25. } catch (SQLException e) {
26. LOG.error("Problem closing connection", e);
27. }
28.}
原来代码的3-5行发生了改变.其中,我们可能对proxool.example:org.hsqldb.jdbcDriver:jdbc:hsqldb:test这段比较有兴趣.
example: 是这个连接池的别名.这是一个你将要引用这个proxool的唯一的标签.
"org.hsqldb.jdbcDriver":这是你的数据库的原始驱动.
"jdbc:hsqldb:test":这个是你的访问你的数据库的url
2. 如果你显式的在启动的时候配置proxool的话,调用会更加简单.配置proxool有很多中方法.如果你已经完成了配置,你仅仅需要proxool的别名就可以了.
For example:
1.Connection connection = null;
文章整理:西部数码--专业提供域名注册、虚拟主机服务
2.try {
4.
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




