|
SQLiteJDBC驱动
这个简单的项目可以让开发者使用Java标准的JDBC API来访问SQLite数据库。它在SQLite 3.3.x C API的基础之上编写了一个小的驱动。 并且将SQLite编译到了本地的JNI库文件当中, 所以只需要把两个文件包拷贝到你的工程里就可以使用了。
授权协议
该发行版遵循BSD协议.
使用方法
下载针对你使用的开发平台的二进制包。解开压缩包把以下两个文件拷贝到你的应用程序目录下:
sqlitejdbc.jar
sqlitejdbc.dll (或者 libsqlitejdbc.so 或者 libsqlitejdbc.jnilib)
在你的代码中用如下方法使用该驱动:
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:filename");
// ... use the database ...
conn.close();
为了你的程序可以调用到驱动的 JAR 文件,你需要把它放入classpath ,或者是把c的库放入环境变量。 例如.
java -cp sqlitejdbc.jar -Djava.library.path=. yourclass
一切的一切就是这么的简单.
编译
解压缩下载的源代码包,设置你的$JAVA_HOME环境变量,然后在命令行下输入:
$ make
具体的过程可以查看发布包中的 README 文件。
速度测试
SQLite、Java 核心、JNI运行速度都是很快的。所以这个SQLite的JDBC驱动运行也很快。以下是我做的一些实验,来证明它的运行速度:
You can make up these numbers yourself by downloading the source tarball and typing make speed.
More tests, comparisons and pretty graphs coming as I find the time.
内存数据库
|
|
Fast Mac
|
Normal Linux
|
|
1000 Inserts (prep)
|
9ms
|
10ms
|
|
1000 Inserts
|
26ms
|
27ms
|
|
With Transactions
|
|
1000 Inserts (prep)
|
7ms
|
8ms
|
|
1000 Inserts
|
25ms
|
25ms
|
文件数据库
|
|
Fast Mac
|
Normal Linux
|
|
With Transactions
|
|
1000 Inserts (prep)
|
20ms
|
37ms
|
|
1000 Inserts
|
37ms
|
53ms
|
操作系统
|
Fast Mac
|
Black Macbook - Intel Core Duo 2ghz
|
|
Normal Liunx
|
AMD Duron 1.6ghz
|
以上的所有测试机都拥有足够大的内存 (阅读次数:)
|