| 1 | --------------------------------------------------------------------- |
|---|
| 2 | What: SQLite 3.3.x JDBC Driver |
|---|
| 3 | Who: David Crawshaw <david@zentus.com> |
|---|
| 4 | When: 2006 |
|---|
| 5 | Why: Because Derby is bloated, HSQLDB has too many capital letters |
|---|
| 6 | in its name and I don't have the time to maintain a full Java |
|---|
| 7 | port of SQLite. |
|---|
| 8 | How: BSD License (dig in) |
|---|
| 9 | --------------------------------------------------------------------- |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | -- USING ------------------------------------------------------------ |
|---|
| 13 | This driver comes in two flavours: Pure Java and native library. The |
|---|
| 14 | Pure Java driver works by running a MIPS version of SQLite inside the |
|---|
| 15 | JVM with NestedVM. To use, download sqlitejdbc-*version*-nested.tgz, |
|---|
| 16 | extract sqlitejdbc-*version*-nested.jar and include in the classpath |
|---|
| 17 | of your project. You can then invoke SQLite using the standard JDBC |
|---|
| 18 | interface: |
|---|
| 19 | |
|---|
| 20 | Class.forName("org.sqlite.JDBC"); |
|---|
| 21 | Connection conn = DriverManager.getConnection( |
|---|
| 22 | "jdbc:sqlite:filename"); |
|---|
| 23 | // ... use the database ... |
|---|
| 24 | conn.close(); |
|---|
| 25 | |
|---|
| 26 | The native library version is faster, but requires a platform and |
|---|
| 27 | operating system specific binary. Place the file |
|---|
| 28 | sqlitejdbc-*version*-native.jar on the classpath and the native |
|---|
| 29 | library sqlitejdbc.dll or libsqlitejdbc.jnilib on the Java library |
|---|
| 30 | path. To do this from the command line: |
|---|
| 31 | |
|---|
| 32 | java -cp sqlitejdbc.jar -Djava.library.path=. yourprog.Main |
|---|
| 33 | |
|---|
| 34 | Alternatively, if you wish to load the native library at runtime, |
|---|
| 35 | set the system property "org.sqlite.lib.path" to the directory |
|---|
| 36 | containing the library. For bundling several binaries, the property |
|---|
| 37 | "org.sqlite.lib.name" can be used if the path property is set. This |
|---|
| 38 | is used as the name of the native library to load. |
|---|
| 39 | |
|---|
| 40 | For a memory database, use a URL without a file name: |
|---|
| 41 | Connection conn = DriverManager.getConnection("jdbc:sqlite:"); |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | -- NOT YET IMPLEMENTED ---------------------------------------------- |
|---|
| 45 | Most aspects of JDBC that are unsupported are done so because SQLite |
|---|
| 46 | doesn't lend itself that way, or I haven't got around to it yet. |
|---|
| 47 | |
|---|
| 48 | - getBlob() / setBlob(): these functions require constantly creating |
|---|
| 49 | instances of java.sql.Blob, which I do not like. The features of |
|---|
| 50 | these functions, such as Stream access cannot be implemented |
|---|
| 51 | efficiently on SQLite anyhow. The only thing that is important is |
|---|
| 52 | retrieving the length of a blob without reading the contents into |
|---|
| 53 | memory. I hope to provide non-JDBC access to this through the API |
|---|
| 54 | mentioned for user-defined functions. |
|---|
| 55 | - ResultSet.isLast(): the only truly evil function in the JDBC spec. |
|---|
| 56 | Even the JavaDoc's accept this: |
|---|
| 57 | Calling the method isLast may be expensive because the JDBC |
|---|
| 58 | driver might need to fetch ahead one row in order to determine |
|---|
| 59 | whether the current row is the last row in the result set. |
|---|
| 60 | |
|---|
| 61 | Supporting this function would bring all the pain of determining |
|---|
| 62 | types, terribly bloat the code and mean a performance hit. It |
|---|
| 63 | will probably always throw an SQLException. Use next() instead. |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | -- COMPILING -------------------------------------------------------- |
|---|
| 67 | Install gcc, gnu make, a JDK, set your $JAVA_HOME and type: |
|---|
| 68 | $ make |
|---|
| 69 | |
|---|
| 70 | On a Unix system, this should compile the driver for your |
|---|
| 71 | architecture and run the test suite. On cygwin you may be lucky and |
|---|
| 72 | only have to rename libsqlitejdbc.so to sqlitejdbc.dll, or other |
|---|
| 73 | problems may appear. |
|---|
| 74 | |
|---|
| 75 | To pass the tests an sqlite binary is needed on the path. |
|---|