My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Links

SQLite JDBC is a library for creating and accessing SQLite database files.

Our SQLiteJDBC library, developed as a part of Xerial project, requires no configuration since all native libraries for Windows, Mac OS X, Linux and pure-java SQLite, which works in any OS enviroment, are assembled into a single JAR (Java Archive) file. The usage is quite simple; Download our sqlite-jdbc library, then append the library (JAR file) to your class path.

See also the Introduction

Public Discussion Forum

Download

Download the latest version of SQLiteJDBC from here.

  • version 3.7.x is the latest one.
    • Do not use sqlite-jdbc-v0xx.jar, which are obsolete libraries but left here for users still using these versions.

If your are a Maven user, follow the instruction described here.

Beta Release

The early releases (beta) of sqlite-jdbc with some advanced features are available from here:

Supported Operating Systems

Since sqlite-jdbc-3.6.19, the natively compiled SQLite engines will be used for the following operating systems:

  • Windows XP, Vista, 7 (x86 architecture, x86_64)
  • Mac OS X 10.4 (Tiger), 10.5(Leopard), 10.6 SnowLeopard (for i386, x86_64, Intel CPU machines)
  • Linux i386 (Intel), amd64 (64-bit X86 Intel processor)

In the other OSs not listed above, the pure-java SQLite is used.

If you want to use the native library for your OS, build the source from scratch.

Usage

  1. Download sqlite-jdbc-(VERSION).jar from http://www.xerial.org/maven/repository/artifact/org/xerial/sqlite-jdbc/, then append this jar file into your classpath.
  2. load the JDBC driver org.sqlite.JDBC from your code. (see the example below)
  • Usage Example (Assuming sqlite-jdbc-(VERSION).jar is placed in the current directory)
  • > javac Sample.java
    > java -classpath ".;sqlite-jdbc-(VERSION).jar" Sample   # in Windows
    or 
    > java -classpath ".:sqlite-jdbc-(VERSION).jar" Sample   # in Mac or Linux
    name = leo
    id = 1
    name = yui
    id = 2
  • Sample.java
  • import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    
    public class Sample
    {
      public static void main(String[] args) throws ClassNotFoundException
      {
        // load the sqlite-JDBC driver using the current class loader
        Class.forName("org.sqlite.JDBC");
        
        Connection connection = null;
        try
        {
          // create a database connection
          connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
          Statement statement = connection.createStatement();
          statement.setQueryTimeout(30);  // set timeout to 30 sec.
          
          statement.executeUpdate("drop table if exists person");
          statement.executeUpdate("create table person (id integer, name string)");
          statement.executeUpdate("insert into person values(1, 'leo')");
          statement.executeUpdate("insert into person values(2, 'yui')");
          ResultSet rs = statement.executeQuery("select * from person");
          while(rs.next())
          {
            // read the result set
            System.out.println("name = " + rs.getString("name"));
            System.out.println("id = " + rs.getInt("id"));
          }
        }
        catch(SQLException e)
        {
          // if the error message is "out of memory", 
          // it probably means no database file is found
          System.err.println(e.getMessage());
        }
        finally
        {
          try
          {
            if(connection != null)
              connection.close();
          }
          catch(SQLException e)
          {
            // connection close failed.
            System.err.println(e);
          }
        }
      }
    }
Powered by Google Project Hosting