1 21 22 package uk.org.primrose.pool.test; 23 24 import java.sql.*; 25 import java.io.*; 26 import java.util.*; 27 import javax.sql.DataSource ; 28 import javax.naming.Context ; 29 import javax.naming.InitialContext ; 30 import javax.naming.NamingException ; 31 32 import uk.org.primrose.pool.standalone.*; 33 34 public class TestPoolControllerStandalone { 35 public static void main(String args[]) throws Exception { 36 new TestPoolControllerStandalone().testIt(); 37 } 38 39 public void testIt() throws IOException { 40 43 49 64 65 Properties p = new Properties(); 66 p.load(new FileInputStream("C:/java/admin.properties")); 67 PoolControllerStandalone.load(p); 68 69 73 90 91 p = new Properties(); 93 p.load(new FileInputStream("C:/java/poolConfig1.properties")); 94 PoolControllerStandalone.load(p); 95 96 p = new Properties(); 98 p.load(new FileInputStream("C:/java/poolConfig2.properties")); 99 PoolControllerStandalone.load(p); 100 101 106 for (int i = 0; i < 10; i++) { 107 System.out.println("Kicking off thread number : " +i); 108 new TestThread().start(); 109 } 110 } 111 112 113 class TestThread extends Thread { 115 public void run() { 116 try { 117 Context ctx = new InitialContext (); 119 DataSource ds = (DataSource )ctx.lookup("java:comp/env/webmap"); 123 Connection c = ds.getConnection(); 125 Statement s = c.createStatement(); 128 ResultSet rs = s.executeQuery("show tables"); 130 int cols = rs.getMetaData().getColumnCount(); 131 132 while (rs.next()) { 133 String line = ""; 135 for (int i = 1; i <= cols; i++) { 136 line += rs.getString(i) +" "; 137 } 138 139 System.out.println(line); 140 } 141 rs.close(); 143 s.close(); 144 c.close(); 145 } catch (NamingException ne) { 146 System.out.println("Problems looking up the pool's JNDI contexts ..."); 147 ne.printStackTrace(); 148 } catch (SQLException sqle) { 149 System.out.println("Problems with the db ..."); 150 sqle.printStackTrace(); 151 } 152 } 153 } 154 } | Popular Tags |