1 33 package smallsql.database; 34 35 import java.io.StringBufferInputStream ; 36 import java.sql.*; 37 import java.util.Properties ; 38 39 public class SSDriver implements Driver { 40 41 static final String URL_PREFIX = "jdbc:smallsql"; 42 43 static SSDriver drv; 44 static { 45 try{ 46 drv = new SSDriver(); 47 java.sql.DriverManager.registerDriver(drv); 48 }catch(Throwable e){ 51 e.printStackTrace(); 52 } 53 } 54 55 56 public Connection connect(String url, Properties info) throws SQLException { 57 Properties props = (Properties )info.clone(); 58 if(!acceptsURL(url)) return null; 59 int idx1 = url.indexOf( ':', 5); if(idx1 > 0){ 61 int idx2 = url.indexOf('?', idx1+1); 62 String dbPath = (idx2 > 0) ? url.substring(idx1+1, idx2) : url.substring(idx1+1); 63 props.setProperty("dbpath", dbPath); 64 if(idx2 > 0){ 65 String propsString = url.substring(idx2+1); 66 propsString = propsString.replace(';', '\n'); 67 try { 68 Properties urlProps = new Properties (props); 69 urlProps.load(new StringBufferInputStream (propsString)); 70 props = urlProps; 71 } catch (Exception e) { 72 e.printStackTrace(); 73 } 74 } 75 } 76 return new SSConnection( props ); 77 } 78 79 80 public boolean acceptsURL(String url){ 81 return url.startsWith(URL_PREFIX); 82 } 83 84 85 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { 86 87 throw new java.lang.UnsupportedOperationException ("Method getPropertyInfo() not yet implemented."); 88 } 89 90 91 public int getMajorVersion() { 92 return 0; 93 } 94 95 96 public int getMinorVersion() { 97 return 16; 98 } 99 100 101 public boolean jdbcCompliant() { 102 return true; 103 } 104 } | Popular Tags |