I'm attracted to the neatness that a single file database provides. What driver/connector library is out there to connect and use SQLite with Java.
I've discovered a wrapper library, http://www.ch-werner.de/javasqlite, but are there other more prominent projects available?
Typo:
java -cp .:sqlitejdbc-v056.jar Test
should be:
java -cp .:sqlitejdbc-v056.jar; Test
notice the semicolon after ".jar" i hope that helps people, could cause a lot of hassle
David Crawshaw project(sqlitejdbc-v056.jar) seems out of date and last update was Jun 20, 2009, source here
I would recomend Xerials fork of Crawshaw sqlite wrapper. I replaced sqlitejdbc-v056.jar with Xerials sqlite-jdbc-3.7.2.jar file without any problem.
Uses same syntax as in Bernie's answer and is much faster and with latest sqlite library.
What is different from Zentus's SQLite JDBC?
EDIT : As usual when you update something, there will be problems in some obscure place in your code(happened to me). Test test test =)
Bernie's post is very helpful. Couldn't vote up (don't have enough reputation :( ). But it Helped a lot. Just to reiterate!
http://www.zentus.com/sqlitejdbc/
Here you can find the latest SQLite JDBC jar. Just add the jar into you classpath and you are done! :) You can run Bernie's sample code to test if everything is fine.
http://souptonuts.sourceforge.net/readme_sqlite_tutorial.html http://www.sqlite.org/lang.html
Here you can find some help on SQL syntax for SQLite. Cheers to SQLite :)
I found your question while searching for information with SQLite and Java. Just thought I'd add my answer which I also posted on my blog.
I have been coding in Java for a while now. I have also known about SQLite but never used it… Well I have used it through other applications but never in an app that I coded. So I needed it for a project this week and it's so simple use!
I found a Java JDBC driver for SQLite. Just add the JAR file to your classpath and import java.sql.*
His test app will create a database file, send some SQL commands to create a table, store some data in the table, and read it back and display on console. It will create the test.db file in the root directory of the project. You can run this example with
java -cp .:sqlitejdbc-v056.jar Test
.The example code leads to a memory leak in Tomcat (after undeploying the webapp, the classloader still remains in memory) which will cause an
outofmemory
eventually. The way to solve it is to use the sqlite-jdbc-3.7.8.jar; it's a snapshot, so it doesn't appear for maven yet.I understand you asked specifically about SQLite, but maybe HSQL database would be a better fit with Java. It is written in Java itself, runs in the JVM, supports in-memory tables etc. and all that features make it quite usable for prototyping and unit-testing.