
SQLite JDBC는 Java에서 SQLite 데이터베이스 파일에 접근하고 생성하기 위한 라이브러리입니다.
저희 SQLiteJDBC 라이브러리는 Windows, macOS, Linux 등을 포함한 주요 OS용 네이티브 라이브러리가 단일 JAR(Java Archive) 파일에 통합되어 있으므로 별도 구성이 필요 없습니다.
➡️ 더 많은 사용 예제와 구성 방법은 USAGE.md에서 확인할 수 있습니다.
SQLite JDBC는 JDBC API를 통해 SQLite 데이터베이스에 접근하기 위한 라이브러리입니다. JDBC의 일반적인 사용법은 JDBC Tutorial 또는 Oracle JDBC Documentation을 참조하세요.
sqlite-jdbc-(VERSION).jar를 받아
클래스패스에 이 jar 파일을 추가합니다.sqlite-jdbc-(VERSION).jar이 현재 디렉토리에 있다고 가정합니다.
> javac Sample.java
> java -classpath ".;sqlite-jdbc-(VERSION).jar" Sample # Windows에서
or
> java -classpath ".:sqlite-jdbc-(VERSION).jar" Sample # macOS 또는 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)
{
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());
}
}
}
}
저희 SQLite JDBC 드라이버 패키지(즉, sqlite-jdbc-(VERSION).jar)에는 세 가지 유형의 네이티브 SQLite 라이브러리(sqlite-jdbc.dll, sqlite-jdbc.jnilib, sqlite-jdbc.so)가 포함되어 있으며, 각각 Windows, macOS, Linux용으로 컴파일되어 있습니다. 프로그램이 org.sqlite.JDBC 드라이버를 로드하면 적절한 네이티브 라이브러리 파일이 운영체제의 임시 폴더에 자동으로 추출됩니다.
sqlite-jdbc-3.6.19부터 다음 운영체제에 대해 네이티브로 컴파일된 SQLite 엔진이 사용됩니다:
위에 나열되지 않은 다른 운영체제에서는 순수 자바 SQLite가 사용됩니다. (3.7.15 이전 버전에 적용)
자신의 운영체제에 맞는 네이티브 라이브러리를 사용하려면 소스를 처음부터 빌드하세요.
Maven Central 또는 releases 페이지에서 다운로드하세요.
<dependencies>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>(version)</version>
</dependency>
</dependencies>
개발 버전의 스냅샷은 Sonatype's snapshots repository에서 확인할 수 있습니다.
프로젝트의 버전은 jar에 포함된 SQLite 라이브러리의 버전을 따르며, 프로젝트의 증분을 나타내는 추가 숫자가 붙습니다.
예를 들어, SQLite 버전이 3.39.2라면 프로젝트 버전은 3.39.2.x가 되며, 여기서 x는 0부터 시작하여 SQLite 버전이 변경되지 않는 각 릴리스마다 증가합니다.
SQLite 버전이 3.40.0으로 업데이트되면 프로젝트 버전도 3.40.0.0으로 업데이트됩니다.
No suitable driver found for jdbc:sqlite: 문제를 해결하려면 shade 플러그인 트랜스포머를 추가해야 할 수 있습니다.
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/services/java.sql.Driver</resource>
</transformer>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>(version)</version>
</dependency>
우리는 항상 다음을 찾고 있습니다:
기여 가이드를 읽어 주세요.
| x86 | x86_64 | armv5 | armv6 | armv7 | arm64 | ppc64 |
|---|
| Windows | ✔ | ✔ | ✔ | ✔ | |||
| macOS | ✔ | ✔ | |||||
| Linux (libc) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| Linux (musl) | ✔ | ✔ | ✔ | ||||
| Android | ✔ | ✔ | ✔ | ✔ | |||
| FreeBSD | ✔ | ✔ | ✔ |