# sqlite-jdbc-crypt **Repository Path**: lztkdr/sqlite-jdbc-crypt ## Basic Information - **Project Name**: sqlite-jdbc-crypt - **Description**: .net sqlite加解密 对应 java sqlite加解密:Connection connection = SQLiteMCSqlCipherConfig.getV3Defaults().withKey("密码").build().createConnection("jdbc:sqlite:file:sqlite文件路径"); - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-10-23 - **Last Updated**: 2023-12-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README = SQLite JDBC Driver :project-version: 3.44.2.0 image:https://img.shields.io/github/actions/workflow/status/willena/sqlite-jdbc-crypt/ci.yml?branch=master[GitHub Workflow Status (branch),link=https://github.com/willena/sqlite-jdbc/actions/workflows/ci.yml?query=branch%3Amaster] image:https://maven-badges.herokuapp.com/maven-central/io.github.willena/sqlite-jdbc/badge.svg[Maven Central,link=https://maven-badges.herokuapp.com/maven-central/io.github.willena/sqlite-jdbc/] image:https://javadoc.io/badge2/io.github.willena/sqlite-jdbc/javadoc.svg[javadoc,link=https://javadoc.io/doc/io.github.willena/sqlite-jdbc] image:https://img.shields.io/nexus/s/io.github.willena/sqlite-jdbc?color=blue&label=maven%20snapshot&server=https%3A%2F%2Foss.sonatype.org%2F[Sonatype Nexus (Snapshots),link=https://oss.sonatype.org/content/repositories/snapshots/io/github/willena/sqlite-jdbc/] SQLite JDBC is a library for accessing and creating https://www.sqlite.org[SQLite] database files in Java. This particular fork uses another native library that provides an implementation of SEE. the native library is provided by [Utelle](http://github.com/utelle) as part of the [SQLite3MultipleCiphers](https://github.com/utelle/SQLite3MultipleCiphers) project Our SQLiteJDBC library requires no configuration since native libraries for major OSs, including Windows, macOS, Linux etc., are assembled into a single JAR (Java Archive) file. == Project Status The project is maintained, but is not being actively developed: - We follow every new version of SQLite and will release a corresponding version of our driver. - Bugs will be investigated, and fixed if possible. - New features are driven by pull requests. == Usage ➡️ More usage examples and configuration are available in link:USAGE.md[USAGE.md] SQLite JDBC is a library for accessing SQLite databases through the JDBC API. For the general usage of JDBC, see https://docs.oracle.com/javase/tutorial/jdbc/index.html[JDBC Tutorial] or https://www.oracle.com/technetwork/java/javase/tech/index-jsp-136101.html[Oracle JDBC Documentation]. . <> `sqlite-jdbc-{project-version}.jar` then append this jar file into your classpath. . https://search.maven.org/remotecontent?filepath=org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar[Download] `slf4j-api-1.7.36.jar` then append this jar file into your classpath. . Open a SQLite database connection from your code. (see the example below) === Example usage Assuming `sqlite-jdbc-{project-version}.jar` and `slf4j-api-1.7.36.jar` are placed in the current directory. [source,shell,subs="attributes+"] ---- > javac Sample.java > java -classpath ".;sqlite-jdbc-{project-version}.jar;slf4j-api-1.7.36.jar" Sample # in Windows or > java -classpath ".:sqlite-jdbc-{project-version}.jar:slf4j-api-1.7.36.jar" Sample # in macOS or Linux name = leo id = 1 name = yui id = 2 ---- === Sample.java [source,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) { 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.getMessage()); } } } } ---- == How does SQLiteJDBC work? Our SQLite JDBC driver package (i.e., `sqlite-jdbc-{project-version}.jar`) contains three types of native SQLite libraries (`sqlitejdbc.dll`, `sqlitejdbc.dylib`, `sqlitejdbc.so`), each of them is compiled for Windows, macOS and Linux. An appropriate native library file is automatically extracted into your OS's temporary folder, when your program loads `org.sqlite.JDBC` driver. === Supported Operating Systems Since sqlite-jdbc-3.6.19, the natively compiled SQLite engines will be used for the following operating systems: |=== | |x86 |x86_64 |armv5 |armv6 |armv7 |arm64 |ppc64 |Windows |✔ |✔ | | |✔ |✔ | |macOS | |✔ | | | |✔ | |Linux (libc) |✔ |✔ |✔ |✔ |✔ |✔ |✔ |Linux (musl) |✔ |✔ | | | |✔ | |Android |✔ |✔ |✔ | | |✔ | |FreeBSD |✔ |✔ | | | |✔ | |=== In the other OSs not listed above, the pure-java SQLite is used. (Applies to versions before 3.7.15) If you want to use the native library for your OS, link:./CONTRIBUTING.md[build the source from scratch]. === GraalVM native-image support Sqlite JDBC supports https://www.graalvm.org/native-image/[GraalVM native-image] out of the box starting from version 3.40.1.0. There has been rudimentary support for some versions before that, but this was not actively tested by the CI. By default, the `sqlitejdbc` library for the compilation target will be included in the native image, accompanied by the required JNI configuration. At runtime, this library will be extracted to the temp folder and loaded from there. For faster startup however, it is recommended to set the `org.sqlite.lib.exportPath` property at build-time. This will export the `sqlitejdbc` library at build-time to the specified directory, and the library will not be included as a resource. As a result, the native image itself will be slightly smaller and the overhead of exporting the library at run-time is eliminated, but you need to make sure the library can be found at run-time. The best way to do this is to simply place the library next to the executable. ==== CLI example [source,shell] ---- native-image -Dorg.sqlite.lib.exportPath=~/outDir -H:Path=~/outDir -cp foo.jar org.example.Main ---- This will place both the `sqlitejdbc` shared library and the native-image output in the `~/outDir` folder. === Maven example This example uses the https://graalvm.github.io/native-build-tools/latest/index.html[native-build-tools] maven plugin: [source,xml] ---- org.graalvm.buildtools native-maven-plugin -Dorg.sqlite.lib.exportPath=${project.build.directory} ---- This will automatically place the `sqlitejdbc` library in the `/target` folder of your project, creating a functional execution environment. When packaging the resulting app, simply include the library in the distribution bundle. == Download Download from https://search.maven.org/artifact/io.github.willena/sqlite-jdbc[Maven Central] or from the https://github.com/willena/sqlite-jdbc-crypt/releases[releases] page. [source,xml,subs="attributes+"] ---- io.github.willena sqlite-jdbc {project-version} ---- Snapshots of the development version are available in https://oss.sonatype.org/content/repositories/snapshots/io/github/willena/sqlite-jdbc/[Sonatype's snapshots repository]. === Project versioning explained The project's version follows the version of the SQLite library that is bundled in the jar, with an extra digit to denote the project's increment. For example, if the SQLite version is `3.39.2`, the project version will be `3.39.2.x`, where `x` starts at 0, and increments with every release that is not changing the SQLite version. If the SQLite version is updated to `3.40.0`, the project version will be updated to `3.40.0.0`. === Hint for maven-shade-plugin You may need to add shade plugin transformer to solve `No suitable driver found for jdbc:sqlite:` issue. [source,xml] ---- META-INF/services/java.sql.Driver ---- [source,xml,subs="attributes+"] ---- io.github.willena sqlite-jdbc {project-version} ---- == How can I help? We are always looking for: - *Reviewers* for issues or PRs, you can check image:https://img.shields.io/github/labels/willena/sqlite-jdbc-crypt/review%20wanted[GitHub labels,link=https://github.com/willena/sqlite-jdbc-crypt/labels/review%20wanted] - *Contributors* to submit PRs, you can check image:https://img.shields.io/github/labels/willena/sqlite-jdbc-crypt/help%20wanted[GitHub labels,link=https://github.com/willena/sqlite-jdbc-crypt/labels/help%20wanted] and image:https://img.shields.io/github/labels/willena/sqlite-jdbc-crypt/good%20first%20issue[GitHub labels,link=https://github.com/willena/sqlite-jdbc-crypt/labels/good%20first%20issue] Please read our link:./CONTRIBUTING.md[contribution] guide.