Home | History | Annotate | Download | only in SQLite
      1 package SQLite;
      2 
      3 import java.sql.*;
      4 import java.util.Properties;
      5 
      6 public class JDBCDriver implements java.sql.Driver {
      7 
      8     public static final int MAJORVERSION = 1;
      9     public static final int MINORVERSION = 2;
     10 
     11     private static java.lang.reflect.Constructor makeConn = null;
     12 
     13     protected Connection conn;
     14 
     15     static {
     16     try {
     17         Class connClass = null;
     18         Class args[] = new Class[2];
     19         args[0] = Class.forName("java.lang.String");
     20         args[1] = args[0];
     21         String jvers = java.lang.System.getProperty("java.version");
     22         String cvers;
     23         if (jvers == null || jvers.startsWith("1.0")) {
     24         throw new java.lang.Exception("unsupported java version");
     25         } else if (jvers.startsWith("1.1")) {
     26         cvers = "SQLite.JDBC1.JDBCConnection";
     27         } else if (jvers.startsWith("1.2") || jvers.startsWith("1.3")) {
     28         cvers = "SQLite.JDBC2.JDBCConnection";
     29         } else if (jvers.startsWith("1.4")) {
     30         cvers = "SQLite.JDBC2x.JDBCConnection";
     31         } else if (jvers.startsWith("1.5")) {
     32         cvers = "SQLite.JDBC2y.JDBCConnection";
     33         try {
     34             Class.forName(cvers);
     35         } catch (java.lang.Exception e) {
     36             cvers = "SQLite.JDBC2x.JDBCConnection";
     37         }
     38         } else {
     39         cvers = "SQLite.JDBC2z.JDBCConnection";
     40         try {
     41             Class.forName(cvers);
     42         } catch (java.lang.Exception e) {
     43             cvers = "SQLite.JDBC2y.JDBCConnection";
     44             try {
     45             Class.forName(cvers);
     46             } catch (java.lang.Exception ee) {
     47             cvers = "SQLite.JDBC2x.JDBCConnection";
     48             }
     49         }
     50         }
     51         connClass = Class.forName(cvers);
     52         makeConn = connClass.getConstructor(args);
     53         java.sql.DriverManager.registerDriver(new JDBCDriver());
     54     } catch (java.lang.Exception e) {
     55         System.err.println(e);
     56     }
     57     }
     58 
     59     public JDBCDriver() {
     60     }
     61 
     62     public boolean acceptsURL(String url) throws SQLException {
     63     return url.startsWith("sqlite:/") ||
     64         url.startsWith("jdbc:sqlite:/");
     65     }
     66 
     67     public Connection connect(String url, Properties info)
     68     throws SQLException {
     69     if (!acceptsURL(url)) {
     70         return null;
     71     }
     72     Object args[] = new Object[2];
     73     args[0] = url;
     74     if (info != null) {
     75         args[1] = info.getProperty("encoding");
     76     }
     77     if (args[1] == null) {
     78         args[1] = java.lang.System.getProperty("SQLite.encoding");
     79     }
     80     try {
     81         conn = (Connection) makeConn.newInstance(args);
     82     } catch (java.lang.reflect.InvocationTargetException ie) {
     83         throw new SQLException(ie.getTargetException().toString());
     84     } catch (java.lang.Exception e) {
     85         throw new SQLException(e.toString());
     86     }
     87     return conn;
     88     }
     89 
     90     public int getMajorVersion() {
     91     return MAJORVERSION;
     92     }
     93 
     94     public int getMinorVersion() {
     95     return MINORVERSION;
     96     }
     97 
     98     public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
     99     throws SQLException {
    100     DriverPropertyInfo p[] = new DriverPropertyInfo[1];
    101     DriverPropertyInfo pp = new DriverPropertyInfo("encoding", "");
    102     p[0] = pp;
    103     return p;
    104     }
    105 
    106     public boolean jdbcCompliant() {
    107     return false;
    108     }
    109 }
    110