1 5 package com.teamkonzept.db; 6 7 import java.sql.*; 8 import java.util.Enumeration ; 9 import java.util.Properties ; 10 import org.apache.log4j.Category; 11 12 19 20 public abstract class TKConnectData { 21 22 24 27 private String connectString; 28 31 private Properties connectProperties; 32 33 private String jdbcProtocol = "jdbc:"; 34 35 39 public TKConnectData( String jdbcSubProtocol, Properties connectProperties ) 40 { 41 this.connectString = jdbcProtocol + jdbcSubProtocol + connectProperties.getProperty("host"); 42 connectProperties.remove("host"); 43 connectProperties.remove("database"); 44 this.connectProperties = connectProperties; 45 } 46 47 public String getConnectString(){ 48 return connectString; 49 } 50 51 public Properties getConnectProperties(){ 52 return connectProperties; 53 } 54 55 59 public void registerDriver( String driverClass ) throws SQLException 60 { 61 try { 62 Class d = Class.forName(driverClass); 63 DriverManager.registerDriver((Driver) d.newInstance()); 64 } 65 catch( SQLException e ) { 66 throw e; 67 } 68 catch( Throwable t ) { 69 throw new NoClassDefFoundError ( t.getMessage() ); 70 } 71 } 72 76 public abstract void initTypeConverter( final Connection conn ) throws SQLException; 77 public abstract TKSQLTypeConverter getTypeConverter(); 78 79 80 85 public String toString () 86 { 87 StringBuffer buffer = new StringBuffer (this.connectString); 88 89 Enumeration keys = this.connectProperties.keys(); 90 91 while (keys.hasMoreElements()) 92 { 93 Object key = keys.nextElement(); 94 95 buffer.append('&') 96 .append(key) 97 .append('=') 98 .append(this.connectProperties.get(key)); 99 } 100 101 return buffer.toString(); 102 } 103 104 } 105 | Popular Tags |