1 6 package org.logicalcobwebs.proxool.examples; 7 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 11 import java.sql.Connection ; 12 import java.sql.DriverManager ; 13 import java.sql.SQLException ; 14 15 22 public class Simple { 23 24 private static final Log LOG = LogFactory.getLog(Simple.class); 25 26 private static void withoutProxool() { 27 28 Connection connection = null; 29 try { 30 Class.forName("org.hsqldb.jdbcDriver"); 31 try { 32 connection = DriverManager.getConnection("jdbc:hsqldb:test"); 33 } catch (SQLException e) { 34 LOG.error("Problem getting connection", e); 35 } 36 37 if (connection != null) { 38 LOG.info("Got connection :)"); 39 } else { 40 LOG.error("Didn't get connection, which probably means that no Driver accepted the URL"); 41 } 42 43 } catch (ClassNotFoundException e) { 44 LOG.error("Couldn't find driver", e); 45 } finally { 46 try { 47 if (connection != null) { 50 connection.close(); 51 } 52 } catch (SQLException e) { 53 LOG.error("Problem closing connection", e); 54 } 55 } 56 } 57 58 private static void withProxool() { 59 60 Connection connection = null; 61 try { 62 Class.forName("org.logicalcobwebs.proxool.ProxoolDriver"); 64 try { 65 connection = DriverManager.getConnection("proxool.example:org.hsqldb.jdbcDriver:jdbc:hsqldb:test"); 67 } catch (SQLException e) { 68 LOG.error("Problem getting connection", e); 69 } 70 71 if (connection != null) { 72 LOG.info("Got connection :)"); 73 } else { 74 LOG.error("Didn't get connection, which probably means that no Driver accepted the URL"); 75 } 76 77 } catch (ClassNotFoundException e) { 78 LOG.error("Couldn't find driver", e); 79 } finally { 80 try { 81 if (connection != null) { 84 connection.close(); 85 } 86 } catch (SQLException e) { 87 LOG.error("Problem closing connection", e); 88 } 89 } 90 } 91 92 95 public static void main(String [] args) { 96 withoutProxool(); 97 withProxool(); 98 } 99 100 } 101 102 139 | Popular Tags |