You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2003/11/10 15:55:59 UTC

cvs commit: jakarta-commons/dbcp/doc ManualPoolingDriverExample.java

dirkv       2003/11/10 06:55:59

  Modified:    dbcp/doc ManualPoolingDriverExample.java
  Log:
  add driver.closePool to example
  update with remarks given on commons-user list
  cleanup example
  
  Revision  Changes    Path
  1.5       +42 -6     jakarta-commons/dbcp/doc/ManualPoolingDriverExample.java
  
  Index: ManualPoolingDriverExample.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/doc/ManualPoolingDriverExample.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ManualPoolingDriverExample.java	9 Oct 2003 21:05:29 -0000	1.4
  +++ ManualPoolingDriverExample.java	10 Nov 2003 14:55:58 -0000	1.5
  @@ -122,7 +122,11 @@
           // system property.
           //
           System.out.println("Loading underlying JDBC driver.");
  -        Class.forName("oracle.jdbc.driver.OracleDriver");
  +        try {
  +            Class.forName("oracle.jdbc.driver.OracleDriver");
  +        } catch (ClassNotFoundException e) {
  +            e.printStackTrace();
  +        }
           System.out.println("Done.");
   
           //
  @@ -132,7 +136,11 @@
           // do it manually.
           //
           System.out.println("Setting up driver.");
  -        setupDriver(args[0]);
  +        try {
  +            setupDriver(args[0]);
  +        } catch (Exception e) {
  +            e.printStackTrace();
  +        }
           System.out.println("Done.");
   
           //
  @@ -169,9 +177,23 @@
               try { stmt.close(); } catch(Exception e) { }
               try { conn.close(); } catch(Exception e) { }
           }
  +
  +        // Display some pool statistics
  +        try {
  +            printDriverStats();
  +        } catch (Exception e) {
  +            e.printStackTrace();
  +        }
  +
  +        // closes the pool
  +        try {
  +            shutdownDriver();
  +        } catch (Exception e) {
  +            e.printStackTrace();
  +        }
       }
   
  -    public static void setupDriver(String connectURI) {
  +    public static void setupDriver(String connectURI) throws Exception {
           //
           // First, we'll need a ObjectPool that serves as the
           // actual pool of connections.
  @@ -200,7 +222,8 @@
           //
           // Finally, we create the PoolingDriver itself...
           //
  -        PoolingDriver driver = new PoolingDriver();
  +        Class.forName("org.apache.commons.dbcp.PoolingDriver");
  +        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
   
           //
           // ...and register our pool with it.
  @@ -211,5 +234,18 @@
           // Now we can just use the connect string "jdbc:apache:commons:dbcp:example"
           // to access our pool of Connections.
           //
  +    }
  +
  +    public static void printDriverStats() throws Exception {
  +        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
  +        ObjectPool connectionPool = driver.getConnectionPool("example");
  +        
  +        System.out.println("NumActive: " + connectionPool.getNumActive());
  +        System.out.println("NumIdle: " + connectionPool.getNumIdle());
  +    }
  +
  +    public static void shutdownDriver() throws Exception {
  +        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
  +        driver.closePool("example");
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org