1 26 package com.nilostep.xlsql.jdbc; 27 28 29 import java.io.*; 30 31 import java.sql.*; 32 33 import java.util.*; 34 import java.util.logging.*; 35 36 37 43 public class xlDriver implements Driver, Constants { 44 45 public static final Logger logger = Logger.getAnonymousLogger(); 46 47 static { 48 try { 49 try { 50 Class.forName("com.mysql.jdbc.Driver"); 51 } catch (Exception e2) { 52 ; 53 } 54 55 try { 56 Class.forName("com.mckoi.JDBCDriver"); 57 } catch (Exception e3) { 58 ; 59 } 60 61 Class.forName("org.hsqldb.jdbcDriver"); 62 DriverManager.registerDriver(new xlDriver()); 63 } catch (Exception e1) { 64 e1.printStackTrace(); 65 } 66 } 67 68 xlConnection c; 70 Properties xlsqlproperties; 71 72 81 public boolean acceptsURL(String url) throws SQLException { 82 return (url.startsWith(URL_PFX_XLS) || url.startsWith(URL_PFX_CSV)); 83 } 84 85 95 public Connection connect(String url, Properties info) 96 throws SQLException { 97 try { 98 Properties p = new Properties(); 99 p.load(new FileInputStream( 100 new File(System.getProperty("user.dir") + File.separator + 101 "xlsql.properties"))); 102 xlsqlproperties = p; 103 } catch (IOException ioe) { 104 xlsqlproperties = info; 105 } 106 107 c = xlConnection.factory(url, xlsqlproperties); 108 109 Runtime.getRuntime().addShutdownHook(new Thread () { 110 public void run() { 111 try { 112 if (c != null) { 113 if (c.closed) { 114 c = null; 115 } 116 } 117 } catch (Exception e) { 118 e.printStackTrace(); 119 } 120 } 121 }); 122 logger.info("Connection to " + 123 c.dbCon.getMetaData().getDatabaseProductName() + 124 " established."); 125 126 return c; 127 } 128 129 134 public int getMajorVersion() { 135 return MAJOR_VERSION; 136 } 137 138 143 public int getMinorVersion() { 144 return MINOR_VERSION; 145 } 146 147 155 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) { 156 DriverPropertyInfo[] pinfo = new DriverPropertyInfo[4]; 163 DriverPropertyInfo p; 164 165 p = new DriverPropertyInfo("sql.url", null); 166 p.description = "jdbc url of SQL engine"; 167 168 169 p.required = false; 171 pinfo[0] = p; 172 173 p = new DriverPropertyInfo("sql.database", null); 174 p.description = "intial context of SQL engine"; 175 176 177 p.required = false; 179 pinfo[1] = p; 180 181 p = new DriverPropertyInfo("sql.user", null); 182 p.description = "db user engine"; 183 184 185 p.required = false; 187 pinfo[2] = p; 188 189 p = new DriverPropertyInfo("sql.password", null); 190 p.description = "db password engine"; 191 192 193 p.required = false; 195 pinfo[3] = p; 196 197 return pinfo; 198 } 199 200 205 public boolean jdbcCompliant() { 206 return JDBC_COMPLIANT; 207 } 208 } | Popular Tags |