1 21 22 import java.sql.*; 23 import java.io.*; 24 import java.util.*; 25 import javax.sql.DataSource ; 26 import javax.naming.Context ; 27 import javax.naming.InitialContext ; 28 import javax.naming.NamingException ; 29 30 import uk.org.primrose.pool.standalone.*; 31 32 public class TestPoolControllerStandalone { 33 public static void main(String args[]) throws Exception { 34 new TestPoolControllerStandalone().testIt(); 35 } 36 37 public void testIt() throws IOException { 38 testUsingStaticPoolConfigFile(); 41 42 46 47 for (int i = 0; i < 10; i++) { 52 System.out.println("Kicking off thread number : " +i); 53 new TestThread().start(); 54 } 55 56 try { 58 Thread.sleep(3000); 59 } catch (InterrupedException ie) { 60 ie.printStackTrace(System.err); 61 } 62 63 PoolControllerStandalone.shutdown(); 65 } 66 67 public void testUsingStaticPoolConfigFile() throws IOException { 68 PoolControllerStandalone.load("C:/java/jakarta-tomcat-5.0.25/conf/poolConfig.properties"); 70 } 71 72 public void testUsingDynamicPropertiesObject() throws IOException { 73 79 94 95 Properties p = new Properties(); 96 p.load(new FileInputStream("C:/java/admin.properties")); 97 PoolControllerStandalone.load(p); 98 99 103 120 121 p = new Properties(); 123 p.load(new FileInputStream("C:/java/poolConfig1.properties")); 124 PoolControllerStandalone.load(p); 125 126 p = new Properties(); 128 p.load(new FileInputStream("C:/java/poolConfig2.properties")); 129 PoolControllerStandalone.load(p); 130 131 } 132 133 134 class TestThread extends Thread { 136 public void run() { 137 try { 138 Context ctx = new InitialContext (); 140 DataSource ds = (DataSource )ctx.lookup("java:comp/env/webmap"); 144 Connection c = ds.getConnection(); 146 Statement s = c.createStatement(); 149 ResultSet rs = s.executeQuery("show tables"); 151 int cols = rs.getMetaData().getColumnCount(); 152 153 while (rs.next()) { 154 String line = ""; 156 for (int i = 1; i <= cols; i++) { 157 line += rs.getString(i) +" "; 158 } 159 160 System.out.println(line); 161 } 162 rs.close(); 164 s.close(); 165 c.close(); 166 } catch (NamingException ne) { 167 System.out.println("Problems looking up the pool's JNDI contexts ..."); 168 ne.printStackTrace(); 169 } catch (SQLException sqle) { 170 System.out.println("Problems with the db ..."); 171 sqle.printStackTrace(); 172 } 173 } 174 } 175 } | Popular Tags |