This document describes how to invoke Proxool. It assumes that you're
familiar with the Java language in general and the JDBC API in particular.
Please visit Sun's JDBC
web site for information about JDBC.
1. If you adapting an existing application then the most transparent
way to switch to Proxool is to simply change the URL you use to connect to the
database. For example:
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.}
To start using Proxool, simply edit lines 3 and 5 (marked in blue):
1.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.}
The first change (line 3) just loads the Proxool JDBC driver (you only have to do this once). The second line
is the one that is interesting, The URL can be broken down into four sections:
proxool.example:org.hsqldb.jdbcDriver:jdbc:hsqldb:test
"example" is the alias for this pool. This is a unique label that we will use to
reference the pool.
"org.hsqldb.jdbcDriver" is the JDBC driver Proxool should
use to connect to the database. (The same one you were originally using).
"jdbc:hsqldb:test" is the URL Proxool should
use to connect to the database. (The same one you were originally using).
2. You will find it a lot easier if you explicitly configure the pools at startup, however. There
are lots of ways of doing this - see here. Once you've done that, it's just
a matter of using the alias to pick up a connection. For example:
1.Connection connection = null;
2.try {
4. try {
5. connection = DriverManager.getConnection("proxool.example");
6. } catch (SQLException e) {
7. LOG.error("Problem getting connection", e);
8. }
...
|