2024-02-08 06:00:05

Java和SQLite

我被单个文件数据库所提供的简洁所吸引。在Java中连接和使用SQLite的驱动程序/连接器库是什么?

我发现了一个包装器库http://www.ch-werner.de/javasqlite,但是还有其他更突出的项目可用吗?


当前回答

有一个新项目SQLJet,它是SQLite的纯Java实现。它还不支持所有的SQLite特性,但是对于一些使用SQLite数据库的Java项目来说可能是一个非常好的选择。

其他回答

有一个新项目SQLJet,它是SQLite的纯Java实现。它还不支持所有的SQLite特性,但是对于一些使用SQLite数据库的Java项目来说可能是一个非常好的选择。

Sqlitejdbc代码可以使用git从https://github.com/crawshaw/sqlitejdbc下载。

# git clone https://github.com/crawshaw/sqlitejdbc.git sqlitejdbc
...
# cd sqlitejdbc
# make

注意:Makefile需要curl二进制文件来下载sqlite库/deps。

我知道你特别问了SQLite,但也许HSQL数据库更适合Java。它本身是用Java编写的,运行在JVM中,支持内存表等,所有这些特性都使它非常适合原型设计和单元测试。

示例代码导致Tomcat中的内存泄漏(在取消部署webapp后,类加载器仍然保留在内存中),这将最终导致内存溢出。解决方法是使用sqlite-jdbc-3.7.8.jar;这是一个快照,所以maven还没有显示。

David Crawshaw项目(sqlitejbc -v056.jar)似乎过时了,最后一次更新是2009年6月20日,来源这里

我推荐Xerials的Crawshaw sqlite包装叉。我用Xerials sqlite-jdbc-3.7.2.jar文件替换了sqlitejdbc-v056.jar,没有任何问题。

使用与伯尼的回答相同的语法,速度更快,并使用最新的sqlite库。

与Zentus的SQLite JDBC有什么不同?

The original Zentus's SQLite JDBC driver http://www.zentus.com/sqlitejdbc/ itself is an excellent utility for using SQLite databases from Java language, and our SQLiteJDBC library also relies on its implementation. However, its pure-java version, which totally translates c/c++ codes of SQLite into Java, is significantly slower compared to its native version, which uses SQLite binaries compiled for each OS (win, mac, linux). To use the native version of sqlite-jdbc, user had to set a path to the native codes (dll, jnilib, so files, which are JNDI C programs) by using command-line arguments, e.g., -Djava.library.path=(path to the dll, jnilib, etc.), or -Dorg.sqlite.lib.path, etc. This process was error-prone and bothersome to tell every user to set these variables. Our SQLiteJDBC library completely does away these inconveniences. Another difference is that we are keeping this SQLiteJDBC libray up-to-date to the newest version of SQLite engine, because we are one of the hottest users of this library. For example, SQLite JDBC is a core component of UTGB (University of Tokyo Genome Browser) Toolkit, which is our utility to create personalized genome browsers.

编辑:像往常一样,当你更新一些东西时,在你的代码中一些模糊的地方会有问题(发生在我身上)。测试测试测试=)