1 14 15 package echoserver; 16 17 import org.quickserver.net.*; 18 import org.quickserver.net.server.*; 19 import org.quickserver.sql.*; 20 import org.quickserver.util.xmlreader.*; 21 22 import java.io.*; 23 import java.util.logging.*; 24 import java.util.*; 25 import java.sql.*; 26 27 public class DBPoolUtil implements org.quickserver.sql.DBPoolUtil { 28 private HashMap dbPool; 29 30 public void setDatabaseConnections(Iterator iterator) 31 throws Exception { 32 dbPool = new HashMap(); 33 while(iterator.hasNext()) { 34 DatabaseConnectionConfig dcc = 35 (DatabaseConnectionConfig)iterator.next(); 36 dbPool.put(dcc.getId(), dcc); 37 } 38 } 39 40 public boolean initPool() { 41 if(dbPool==null) 42 throw new IllegalStateException ("Call setDatabaseConnections first.!!"); 43 Iterator iterator = dbPool.keySet().iterator(); 44 try { 45 while(iterator.hasNext()) { 46 DatabaseConnectionConfig dcc = (DatabaseConnectionConfig) 47 dbPool.get( (String )iterator.next() ); 48 Class.forName(dcc.getDriver()); 49 } 50 return true; 51 } catch(Exception e) { 52 System.err.println("In DBPoolUtil.initPool : "+e); 53 return false; 54 } 55 } 56 57 public boolean clean() { 58 dbPool = null; 59 return true; 60 } 61 62 public Connection getConnection(String id) throws Exception { 63 DatabaseConnectionConfig dcc = (DatabaseConnectionConfig) 64 dbPool.get( id ); 65 return DriverManager.getConnection(dcc.getUrl(), dcc.getUsername(), 66 dcc.getPassword()); 67 } 68 } 69 | Popular Tags |